Accounts
Gasless smart accounts for AI agent registration via CDP Paymaster
Overview
@a3stack/accounts removes the biggest barrier to on-chain agent identity: gas fees. Using Coinbase Developer Platform's Paymaster service, agents can register on ERC-8004 with zero ETH — no wallet funding, no gas estimation, no friction.
Under the hood, it creates an ERC-4337 smart account on Base, owned by a CDP-managed server wallet. All transactions are automatically gas-sponsored by the CDP Paymaster.
CDP Paymaster sponsors gas for all UserOperations targeting the ERC-8004 registry. Your agents never need ETH to register. Currently supported on Base Mainnet and Base Sepolia.
Installation
$npm install @a3stack/accountsRequires Node.js 22+ and a CDP account with an API key and Wallet Secret.
CDP Setup
Before using the package, you need three credentials from the CDP portal:
- API Key ID & Secret — Create at portal.cdp.coinbase.com → API Keys. Enable View and Manage Policies permissions.
- Wallet Secret — Generate at portal.cdp.coinbase.com → Server Wallet → Accounts. This is an EC P-256 private key (PKCS8 format, base64-encoded).
- Paymaster Allowlist — Go to portal.cdp.coinbase.com → Paymaster, select Base Mainnet, and add
0x8004A169FB4a3325136EB29fA0ceB6D2e539a432to the contract allowlist.
# .env
CDP_API_KEY_ID=your-api-key-id
CDP_API_KEY_SECRET=your-api-key-secret
CDP_WALLET_SECRET=your-wallet-secretQuick Start
Create a Smart Account
import { createAgentAccount } from "@a3stack/accounts";
// Create a gasless smart account on Base
const agent = await createAgentAccount({
apiKeyId: process.env.CDP_API_KEY_ID!,
apiKeySecret: process.env.CDP_API_KEY_SECRET!,
walletSecret: process.env.CDP_WALLET_SECRET!,
}, {
name: "my-agent", // idempotent — same name returns same account
});
console.log("Smart account:", agent.address);
console.log("Owner EOA:", agent.ownerAddress);
console.log("Network:", agent.network); // "base"createAgentAccount() is idempotent — calling it with the same name returns the same smart account address every time. The smart account is deployed on-chain with its first UserOperation (CREATE2 deterministic addressing).
Register on ERC-8004
// Register on ERC-8004 with zero gas cost
const result = await agent.register({
name: "My Agent",
description: "An autonomous AI agent that does cool things",
services: [
{ type: "website", url: "https://myagent.ai" },
{ type: "mcp", url: "https://api.myagent.ai/mcp" },
],
x402Support: true,
});
console.log("Tx:", result.transactionHash);
console.log("Gas cost:", result.gasCost); // 0
console.log("Sponsored:", result.sponsored); // trueThe register() method builds an ERC-8004 registration JSON, encodes it as a data URI, and sends a gasless UserOperation to the registry contract. CDP Paymaster covers all gas costs.
One-Shot Registration
For the simplest flow — create account and register in one call:
import { gaslessRegister } from "@a3stack/accounts";
// One-shot: create account + register in a single call
const result = await gaslessRegister(
{
apiKeyId: process.env.CDP_API_KEY_ID!,
apiKeySecret: process.env.CDP_API_KEY_SECRET!,
walletSecret: process.env.CDP_WALLET_SECRET!,
},
{
name: "My Agent",
description: "Registers with zero friction",
accountName: "my-agent", // optional
}
);
console.log("Registered at:", result.smartAccountAddress);
console.log("BaseScan:", `https://basescan.org/tx/${result.transactionHash}`);Custom UserOperations
The smart account isn't limited to registration — send any gasless transaction via sendUserOperation():
// Send any gasless transaction via the smart account
const result = await agent.sendUserOperation([
{
to: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
value: 0n,
data: "0x...", // any calldata
},
]);
console.log("Tx:", result.transactionHash);
// Gas sponsored by CDP Paymaster — $0 costAPI Reference
createAgentAccount(credentials, options?)
Creates or retrieves a gasless smart account on Base.
| Param | Type | Description |
|---|---|---|
credentials.apiKeyId | string | CDP API Key ID |
credentials.apiKeySecret | string | CDP API Key Secret |
credentials.walletSecret | string | CDP Wallet Secret (EC P-256 PKCS8) |
options.name | string? | Account name (idempotent). Default: "a3stack-agent" |
options.testnet | boolean? | Use Base Sepolia instead of mainnet |
Returns an AgentAccount with:
address— Smart account address (ERC-4337)ownerAddress— Owner EOA addressnetwork— "base" or "base-sepolia"register(opts)— Register on ERC-8004 (gasless)sendUserOperation(calls)— Send any gasless UserOperation
gaslessRegister(credentials, options)
Convenience function that creates an account and registers in one call. Accepts all RegisterOptions plus optional accountName and testnet.
How It Works
- CDP Server Wallet — Creates a managed EOA (private key secured in CDP's TEE)
- Smart Account — Creates an ERC-4337 smart account owned by the EOA (deterministic via CREATE2)
- UserOperation — Encodes the
register(agentURI)call and submits it - CDP Paymaster — Automatically sponsors the gas fee (you pay $0)
- Bundler — CDP bundles and submits the UserOperation to Base
- On-chain — Agent is registered as an ERC-721 NFT on ERC-8004 registry
CDP charges your account for sponsored gas at actualGas × ethPrice × 1.07 (7% markup). At current Base gas prices, a typical registration costs fractions of a cent. Apply for up to $15K in gas credits via the Base Gasless Campaign.
Supported Networks
| Network | Status |
|---|---|
| Base Mainnet | ✅ Supported |
| Base Sepolia | ✅ Supported |
| Other EVM chains | Use @a3stack/identity (requires ETH for gas) |