Create an account for an agent, fund it on Celo Sepolia and send a first transfer before you wire it into x402 or MPP
This page is for agent developers who need an account their agent can sign with and some test funds. It ends with a transfer on Celo Sepolia, the testnet, so you know the account works before you add payments. The account works wherever an agent page asks for a key on Celo Sepolia.
Prerequisites
Node.js 20.6 or later
npm install viem
Generate an account
An agent signs with a private key. Create one with viem:
Run it once with node generate-key.mjs. Put the AGENT_PRIVATE_KEY line in a .env file that is in .gitignore, and keep the address for the next step.
Use a separate key for testing. Anyone who has the key controls everything the account holds. Never commit it, and never reuse a testnet key on mainnet.
Get test funds
The account needs CELO on Celo Sepolia (chain ID 11142220) to pay gas.
Open the Celo Sepolia faucet and request CELO for the address from the previous step. It sends 1 CELO per request without signing in.
If you plan to test x402 or MPP, also get test USDC from the Circle faucet. The Celo Sepolia USDC token has 6 decimals, so 1 USDC is 1000000 base units.
This script reads the balance and sends a small amount of CELO to another address. Replace the recipient with an address you control.
// first-transfer.mjs// Celo Sepolia (11142220), native CELO, 18 decimalsimport { createPublicClient, createWalletClient, http, parseEther, formatEther } from "viem";import { privateKeyToAccount } from "viem/accounts";import { celoSepolia } from "viem/chains";const account = privateKeyToAccount(process.env.AGENT_PRIVATE_KEY);const publicClient = createPublicClient({ chain: celoSepolia, transport: http() });const walletClient = createWalletClient({ account, chain: celoSepolia, transport: http() });const balance = await publicClient.getBalance({ address: account.address });console.log("Balance:", formatEther(balance), "CELO");const hash = await walletClient.sendTransaction({ to: "0xYourOtherAddress", // example, replace with an address you control value: parseEther("0.01"),});const receipt = await publicClient.waitForTransactionReceipt({ hash });console.log("Status:", receipt.status, "Hash:", hash);
Run it with your key in the environment, for example node --env-file=.env first-transfer.mjs.You are done when it prints Status: success. Look the hash up on the Celo Sepolia explorer to see the transaction.
Troubleshooting
Symptom
Cause
Fix
insufficient funds for gas
The account has no CELO on Celo Sepolia
Request CELO from the faucet, then check the balance
Balance: 0 CELO after the faucet
The faucet sent funds to a different address, or you are reading the balance on Celo mainnet
Check the address and that your client uses Celo Sepolia (chain ID 11142220)
USDC transfer amount is off by a factor of 10^12
USDC has 6 decimals and CELO has 18
Use parseUnits("1", 6) for USDC and parseEther for CELO
Related
x402 - charge or pay per request with this account