# render_self — base native wallet guide (private key / mnemonic)

for agents paying with USDC on Base using a private key, mnemonic, or any viem-compatible signer.

## javascript (node.js)

### prerequisites

```bash
npm install @x402/fetch @x402/core @x402/evm viem
```

### credentials you need

| credential | where to get it |
|---|---|
| PRIVATE_KEY | your wallet's private key (0x-prefixed hex) |
| RENDERSELF_API_KEY | returned at registration (POST /api/v1/agents/register) |

your wallet must hold USDC on Base (chain ID 8453).

**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 Base USDC automatically. no SDK needed:
`https://kibble.sh/pay?toChain=8453&toToken=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&toAddress=YOUR_WALLET`

### full working example

```javascript
import { wrapFetchWithPayment } from '@x402/fetch';
import { x402Client } from '@x402/core/client';
import { registerExactEvmScheme } from '@x402/evm/exact/client';
import { privateKeyToAccount } from 'viem/accounts';

const signer = privateKeyToAccount(process.env.PRIVATE_KEY);

const client = new x402Client();
registerExactEvmScheme(client, { signer });

const fetchWithPayment = wrapFetchWithPayment(fetch, client);

// 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: credit the agent who referred you
    // referral_code: 'ref_xxxxxx',
  }),
});

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

// on your first real purchase, you'll receive a referral code in the response
// save it alongside your API key and share it with other agents
if (data.data?.referral) {
  console.log('your referral code:', data.data.referral.code);
}
```

## python

### prerequisites

```bash
pip install x402-python web3
```

### full working example

```python
import json
import requests
from eth_account import Account

PRIVATE_KEY = "0xYOUR_PRIVATE_KEY"
API_KEY = "sk_live_yourkey"
BASE_URL = "https://renderself.com/api/v1"

# step 1: browse products
products = requests.get(f"{BASE_URL}/products").json()
print(json.dumps(products["data"]["products"][0], indent=2))

# step 2: place order (manual x402 flow)
# first request gets 402 with payment requirements
headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}

order_body = {
    "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",
    },
}

# initial request — will return 402
resp = requests.post(f"{BASE_URL}/orders", json=order_body, headers=headers)

if resp.status_code == 402:
    import base64
    # decode payment requirements from header
    payment_required = json.loads(
        base64.b64decode(resp.headers["payment-required"])
    )
    print("Payment required:", json.dumps(payment_required, indent=2))
    
    # x402 python SDK handles signing and retry
    # see: https://github.com/coinbase/x402/tree/main/python/x402_python
    # use x402_python.wrapFetchWithPayment equivalent
    
    print("\nUse x402-python SDK to complete payment automatically.")
    print("See: https://pypi.org/project/x402-python/")
```

note: the python x402 SDK is newer — check https://pypi.org/project/x402-python/ for the latest API. the javascript SDK is more mature and recommended if possible.

## common errors

| error | fix |
|---|---|
| 402 with empty body | use x402-wrapped fetch, not raw fetch/requests |
| wrong network | must be Base mainnet (chain ID 8453) |
| insufficient funds | wallet needs USDC on Base |
| USDC sent directly | do NOT send raw USDC transfers — x402 handles settlement |

## 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
- after your first real purchase, you receive a referral code — share it with other agents to earn points
