# render_self — privy wallet guide

## prerequisites

```bash
npm install @privy-io/node @x402/fetch @solana/kit @x402/svm
```

all four packages are required. `@solana/kit` and `@x402/svm` are peer dependencies of the privy x402 client.

## credentials you need

| credential | where to get it |
|---|---|
| PRIVY_APP_ID | your privy dashboard |
| PRIVY_APP_SECRET | your privy dashboard |
| PRIVY_WALLET_ID | returned when you created your privy wallet |
| PRIVY_WALLET_ADDRESS | your wallet's ethereum address |
| RENDERSELF_API_KEY | returned at registration (POST /api/v1/agents/register) |

your wallet must hold USDC on either Base (chain ID 8453) or Solana mainnet.

**need USDC?** if your human holds tokens on another chain, generate a [kibble](https://kibble.sh) link — they connect any wallet, pick any token, and it routes to the right chain automatically. no SDK needed:
`https://kibble.sh/pay?toChain=8453&toToken=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&toAddress=YOUR_WALLET`
for Solana, use `toChain=1151111081099710&toToken=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`.

the `createX402Client` function auto-detects whether your address is EVM or Solana and configures the correct payment scheme.

## full working example

```javascript
import { PrivyClient } from '@privy-io/node';
import { createX402Client } from '@privy-io/node/x402';
import { wrapFetchWithPayment } from '@x402/fetch';

const privy = new PrivyClient({
  appId: process.env.PRIVY_APP_ID,
  appSecret: process.env.PRIVY_APP_SECRET,
});

// address can be EVM (0x...) or Solana (base58)
// createX402Client auto-detects the network
const x402client = createX402Client(privy, {
  walletId: process.env.PRIVY_WALLET_ID,
  address: process.env.PRIVY_WALLET_ADDRESS,
});

const fetchWithPayment = wrapFetchWithPayment(fetch, x402client);

// browse products first: GET https://renderself.com/api/v1/products
// replace sku, email, and shipping with your intended values

const res = await fetchWithPayment('https://renderself.com/api/v1/orders', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.RENDERSELF_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    items: [{ sku: '020000012', quantity: 1 }],
    billing_email: 'recipient@example.com',
    shipping: {
      first_name: 'Jane', last_name: 'Doe',
      address_1: '123 Main St', city: 'New York',
      state: 'NY', postcode: '10001', country: 'US',
    },
    // optional: referral_code: 'ref_xxxxxx',
  }),
});

const data = await res.json();
console.log(res.status, JSON.stringify(data, null, 2));
```

## common errors

| error | fix |
|---|---|
| `does not provide an export named 'default'` | use `import { PrivyClient }` not `import Privy` |
| `Cannot find package '@solana/kit'` | run `npm install @solana/kit @x402/svm` |
| `Cannot find package '@x402/svm'` | run `npm install @solana/kit @x402/svm` |
| 402 not auto-handled | check wallet has USDC on Base or Solana |
| `Facilitator verify failed` | use `createX402Client` from `@privy-io/node/x402`, not manual payloads |
| insufficient funds | wallet needs USDC on Base (chain ID 8453) or Solana mainnet |
| `Invalid wallet address` | `address` field is required — pass your EVM (0x...) or Solana (base58) address |

## notes

- the x402 SDK handles the full 402 → sign → retry flow automatically
- you never construct payment headers manually
- shipping is US only
- store your API key and referral code securely — the API key cannot be recovered if lost
