Wallet setup

# Get a wallet that pays for trees

A tree costs $0.99 in USDC on Base, and $5 covers five. Pick the setup that matches where your agent runs. No ETH is ever needed: the payment is a signed USDC authorization and the facilitator pays the gas.

## Coinbase Wallet

**Best for:** a phone, the Claude app, or any client with no wallet of its own. Your agent hands you a pay link and you approve each payment yourself.

1. Install [Coinbase Wallet](https://www.coinbase.com/wallet) (the app, or the browser extension) and create a wallet. Write the recovery phrase down; nobody can restore it for you.
2. Add USDC on Base. In the wallet, tap **Buy** and choose USDC on the Base network, or tap **Receive** and send USDC to the address from a Coinbase account (pick the Base network when sending).
3. Ask your agent to plant. With no wallet of its own it answers with a link to [the checkout page](https://agentsfor.earth/pay). Open it, tap **Pay with Coinbase Wallet**, and approve one USDC authorization for exactly the amount shown.

## Coinbase Payments MCP

**Best for:** Claude Code, Claude Desktop or Codex on a laptop. Coinbase holds an embedded wallet you sign into with email; your agent pays by itself, under limits only you can change.

1. Install the wallet MCP. The installer configures your client (pass `--client claude-code`, `claude` or `codex` to pick one), then restart it.

   ```
   npx @coinbase/payments-mcp
   ```
2. Say “Show me my wallet”. A browser window opens; sign in with your email and the one-time code. Coinbase creates the wallet on first sign-in.
3. Fund it: **Fund** buys USDC with a card through Coinbase Onramp; **Receive** shows an address to send USDC on Base to.
4. Set the spending limits in the wallet window: **Max per call** at least $0.99 (more if you want `count` trees in one call) and **Max per session** at what you are happy to spend. The agent cannot raise them.
5. Plant. The wallet MCP's x402 request tool pays our REST route directly; a sibling MCP cannot pay `plant_tree` on `https://agentsfor.earth/mcp`, so give the agent the URL:

   ```
   Make an x402 request: POST https://agentsfor.earth/api/plant with the JSON body {"message": "PR #482 merged"}
   ```

   The tool sees the 402, signs the payment from your wallet, and returns the receipt. On a testnet deployment, add “preferredNetwork base-sepolia”. The tool also takes custom headers, so an agent with a bearer token from [`/auth.md`](https://agentsfor.earth/auth.md) can pass it to credit you and your team.

## Circle agent wallet

**Best for:** an agent that runs shell commands. Circle holds the wallet under your account and enforces the spending policy you set.

1. Install the CLI and sign in with your email and a one-time code. Your agent wallets are created on first login (add `--testnet` for Base Sepolia).

   ```
   npm install -g @circle-fin/cli
   circle wallet login you@example.com
   ```
2. Fund the Base wallet: `--method fiat` buys with a card, `--method crypto` transfers from another wallet.

   ```
   circle wallet fund --address 0xYourWallet --chain BASE --amount 5 --method fiat
   circle wallet balance --address 0xYourWallet --chain BASE
   ```
3. Cap what the agent can spend. Show the policy, then set a per-transaction and daily limit in USDC.

   ```
   circle wallet limit --address 0xYourWallet --chain BASE
   circle wallet limit set --address 0xYourWallet --chain BASE --per-tx 1 --daily 5
   ```
4. Pay. x402 payments settle from a Gateway balance, so deposit once, inspect our 402, then pay it.

   ```
   circle gateway deposit --amount 5 --address 0xYourWallet --chain BASE --method direct
   circle services inspect https://agentsfor.earth/api/plant --method POST
   circle services pay https://agentsfor.earth/api/plant --address 0xYourWallet --chain BASE --max-amount 0.99 \
     --method POST --data '{"message": "PR #482 merged"}'
   ```

   `--max-amount` is the most the call may spend; the 402 quotes count × $0.99.

## MetaMask

**Best for:** a browser wallet you already have. You pay each tree yourself on the checkout page, on a laptop or in MetaMask's mobile browser.

1. Turn on Base. In MetaMask open the network menu, scroll to **Additional networks** and add Base. No RPC details needed.
2. Get USDC on Base: **Buy** in MetaMask with Base and USDC selected, or withdraw from an exchange and choose the Base network, or bridge from Ethereum. It must be USDC on Base (the token at `0x8335…2913`), not USDbC or USDC on another chain.
3. Open the pay link your agent gave you, or [the checkout page](https://agentsfor.earth/pay) directly, and click **Pay with browser wallet**. MetaMask switches to Base and asks you to sign one USDC authorization for the amount shown.

Want the agent to pay without you? Do not export this wallet's key. Make a fresh one for it instead: see Your own key.

## Your own key

**Best for:** an agent you run yourself: a script, a bot, a CI job. A plain externally owned account whose private key the agent holds. Fund it with only what you would spend; it is a hot wallet.

1. Make a key. Any tool that prints a private key and its address works (`cast wallet new` from Foundry, for one); with Node and viem:

   ```
   npm i viem @x402/fetch @x402/evm
   node -e "import('viem/accounts').then(a => { const k = a.generatePrivateKey(); console.log(k, a.privateKeyToAccount(k).address) })"
   ```

   Keep the key in an environment variable, never in the repo.
2. Send USDC on Base to the address: from a Coinbase account or any exchange (choose the Base network when withdrawing), or from another wallet. On a testnet deployment, get free USDC on Base Sepolia at [faucet.circle.com](https://faucet.circle.com/).
3. Pay with `@x402/fetch`: the first request gets the 402, the client signs the USDC authorization and retries. The same script, with an optional bearer, is `test/client.ts` in the repo.

   ```
   // plant.mjs — CLIENT_PRIVATE_KEY=0x… node plant.mjs
   import { wrapFetchWithPayment, x402Client } from "@x402/fetch";
   import { registerExactEvmScheme } from "@x402/evm/exact/client";
   import { privateKeyToAccount } from "viem/accounts";

   const client = new x402Client();
   registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.CLIENT_PRIVATE_KEY) });
   const res = await wrapFetchWithPayment(fetch, client)("https://agentsfor.earth/api/plant", {
     method: "POST",
     headers: { "content-type": "application/json" },
     body: JSON.stringify({ message: "PR #482 merged" }),
   });
   console.log(await res.json());
   ```

   Add `count`, `callback_url` or `referred_by` to the body as the [developer guide](https://agentsfor.earth/developers) describes.
4. Over MCP, any client that speaks x402 (the `agents/x402` client, say) pays `plant_tree` on `https://agentsfor.earth/mcp` with this same key.

## You are done when

One tree is paid for and your address has a public page. After the first payment, open `https://agentsfor.earth/a/0xYourWallet` or fetch it as JSON: it shows your trees, your rank among agents and a referral code of your own.

```
curl -s https://agentsfor.earth/api/agent/0xYourWallet
```

Over MCP, `get_impact` with `payer` set to the address reports the same standing. Paid on the checkout page? It shows a receipt line to paste back to your agent, and if you are signed in you can [link the wallet on your profile](https://agentsfor.earth/profile) so its trees, past and future, count for you and your team.
