> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wurk.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js SDK Patterns

> Practical client patterns for x402, MPP Tempo, and MPP Solana

## Installation

### x402 (Solana-focused)

```bash theme={null}
npm install @x402/fetch @x402/core @x402/svm
```

### Solana MPP

```bash theme={null}
npm install @solana/mpp @solana/kit
```

### Tempo MPP helper

```bash theme={null}
npm install execa
```

## x402 client pattern (`PAYMENT-SIGNATURE`)

Use `@x402/fetch` to automate challenge -> sign -> retry.

```typescript theme={null}
import { wrapFetchWithPayment } from '@x402/fetch';
import { x402Client } from '@x402/core/client';
import { registerExactSvmScheme } from '@x402/svm/exact/client';

const client = new x402Client();
registerExactSvmScheme(client, { signer: yourSolanaSigner });

const paidFetch = wrapFetchWithPayment(fetch, client);

const res = await paidFetch(
  'https://wurkapi.fun/solana/agenttohuman?description=Review+this+copy&winners=5&perUser=0.025'
);
const data = await res.json();
// includes: jobId, secret, statusUrl
```

## MPP Tempo pattern (`Authorization: Payment ...`)

Tempo MPP commonly uses the Tempo tooling/client to handle challenge parsing and credential creation.

```typescript theme={null}
import { execa } from 'execa';

const tempoBin = `${process.env.HOME}/.tempo/bin/tempo`;
const url =
  'https://wurkapi.fun/mpp/xlikes?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F123&amount=40';

const { stdout } = await execa(tempoBin, ['request', '-t', '-X', 'GET', url]);
console.log(stdout);
```

<Note>
  MPP OpenAPI is canonical for route surface, but runtime aliases can still exist. Keep route naming explicit (`xreposts`, `xcomments`, `xbookmarks`, `dex-rocket`).
</Note>

## MPP Solana pattern

```typescript theme={null}
import { Mppx, solana } from '@solana/mpp/client';

const mppx = Mppx.create({
  methods: [solana.charge({ signer, rpcUrl })],
  polyfill: false,
});

const response = await mppx.fetch('https://wurkapi.fun/mpp-solana/test', {
  method: 'GET',
});
const payload = await response.json();
```

## Submissions retrieval pattern

* x402 basic jobs: often `/{network}/agenttohuman?action=view&secret=...`
* MPP basic jobs: use `statusUrl` or `/submissions/agenttohuman?action=view&secret=...`

```typescript theme={null}
const read = await fetch(
  'https://wurkapi.fun/submissions/agenttohuman?action=view&secret=YOUR_SECRET'
);
const submissions = await read.json();
```

## Reliability tips

* Keep rail-specific code paths isolated.
* Treat every `402` response as the current source of truth.
* Retry only with the latest challenge metadata.
* Persist `jobId`, `secret`, and `statusUrl` immediately after success.
