The Financial Layer for Autonomous AI Agents
ERC-8004 Identity + x402 Gasless Payments + MoltPay CLI
Quick Start β’ MoltPay CLI β’ SDK Reference β’ Examples
A wallet-agnostic SDK for building autonomous AI agents on Avalanche with:
- π ERC-8004 - On-chain agent identity, reputation, and validation
- πΈ x402 Payments - Gasless payments via 0xGasless facilitator
- π¦ MoltPay CLI - Interactive command-line for agent registration & payments
- π€ LangChain Tools - Pre-built tools for AI agent frameworks
- π Fetch.ai Integration - Optional ASI-1 agent integration
npm install @0xgasless/agent-sdk ethers# Install globally for CLI access
npm install -g @0xgasless/agent-sdk
# Or use npx without installing
npx @0xgasless/agent-sdk moltpay --helpnpm install @0xgasless/agent-sdk ethers dotenv# .env
PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HERE
RPC_URL=https://api.avax-test.network/ext/bc/C/rpcimport { AgentSDK, fujiConfig } from '@0xgasless/agent-sdk';
import { Wallet, JsonRpcProvider } from 'ethers';
import 'dotenv/config';
// Create wallet from private key
const provider = new JsonRpcProvider(process.env.RPC_URL);
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);
// Initialize SDK
const sdk = new AgentSDK({
networks: fujiConfig.networks,
defaultNetwork: 'fuji',
signer: wallet,
});
// Register agent on ERC-8004
const agentId = await sdk.erc8004.identity().register('ipfs://QmAgentMetadata...');
console.log('Agent registered with ID:', agentId);MoltPay is the interactive CLI for managing agent wallets, registrations, and payments.
# Global install (recommended)
npm install -g @0xgasless/agent-sdk
# Verify installation
moltpay --help| Command | Description |
|---|---|
moltpay init |
Initialize agent wallet and environment |
moltpay register |
Register agent identity on ERC-8004 |
moltpay pay |
Send crypto payments |
moltpay verify |
Verify agent on MoltBook social graph |
moltpay initFollow the interactive prompts:
- Select network: Avalanche Fuji (Testnet) or Avalanche Mainnet
- Enter private key or generate new wallet
This creates a .env file with your configuration.
moltpay registerThis will:
- Check if you already have an identity
- Prompt for agent name and service domain
- Mint your ERC-8004 identity NFT on-chain
# Interactive mode
moltpay pay
# Direct mode
moltpay pay 10 USDC 0xRecipientAddressmoltpay verifyLinks your on-chain identity to your social presence.
# π§ COMING SOON - Hosted version with managed wallets
# npx @0xgasless/moltpay-hosted login
# npx @0xgasless/moltpay-hosted dashboard| Contract | Address |
|---|---|
| IdentityRegistry | 0x06d49e79da8a241dd2c412bf5d22e19c619a39d1 |
| ReputationRegistry | 0x29A62d678dCc581414BB3A74dF27E99c17e60dD7 |
| ValidationRegistry | 0xa490b79113d8ef4e7c7912759a3fcaff8a58cd05 |
| ValidationPlugin | 0x83dab1f7be37c5c4b84743b72642c9651de7f12b |
| Component | Value |
|---|---|
| Facilitator URL | https://x402.0xgasless.com |
| Relayer Contract | 0x457Db7ceBAdaF6A043AcE833de95C46E982cEdC8 |
| EIP-712 Domain | { name: "A402", version: "1", chainId: 43114 } |
| Token | Address | Decimals |
|---|---|---|
| USDC (Native) | 0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E |
6 |
| USDT (Native) | 0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7 |
6 |
| USDC.e (Bridged) | 0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664 |
6 |
| USDT.e (Bridged) | 0xc7198437980c041c805A1EDcbA50c1Ce5db95118 |
6 |
| Contract | Address |
|---|---|
| IdentityRegistry | 0x372d406040064a9794d14f3f8fec0f2e13e5b99f |
| ReputationRegistry | 0x8B106121EeEC204a1EA012E8560090a85d4C5350 |
| ValidationRegistry | 0x6ab685d73513918a5d76d90cbc089583b92f029e |
| ValidationPlugin | 0x6b35bEc82E5623dbc67Aa921dB10fF719C77E1fB |
| Component | Value |
|---|---|
| Facilitator URL | http://testnet.0xgasless.com |
| Relayer Contract | 0x8BD697733c31293Be2327026d01aE393Ab2675C4 |
import { AgentSDK, fujiConfig } from '@0xgasless/agent-sdk';
const sdk = new AgentSDK({
networks: fujiConfig.networks,
defaultNetwork: 'fuji',
signer: wallet, // Any ethers.Signer
});
// Get wallet address
const address = await sdk.getAddress();
// Access ERC-8004 clients
const identity = sdk.erc8004.identity();
const reputation = sdk.erc8004.reputation();
const validation = sdk.erc8004.validation();
// Access x402 facilitator
const facilitator = sdk.getFacilitator();import { IdentityV2 } from '@0xgasless/agent-sdk';
// Register new agent
const agentId = await identity.register('ipfs://metadata-uri');
// Get agent by owner
const agentId = await identity.getAgentIdByOwner('0xOwnerAddress');
// Get agent metadata URI
const uri = await identity.tokenURI(agentId);
// Check balance
const count = await identity.balanceOf('0xAddress');import { ReputationV2 } from '@0xgasless/agent-sdk';
// Get reputation score
const score = await reputation.getScore(agentId);
// Get reputation history
const history = await reputation.getHistory(agentId);import { FacilitatorClient, x402Fetch } from '@0xgasless/agent-sdk';
// Create payment payload
const payload = await sdk.x402.createPaymentPayload({
to: '0xRecipient',
amount: '5000000', // 5 USDT (6 decimals)
token: '0xUSDTAddress',
});
// Use x402 fetch for gasless requests
const response = await x402Fetch('https://api.example.com/paid-endpoint', {
method: 'POST',
headers: { 'X-402-Payment': JSON.stringify(payload) },
});import { getAgentTools, registerAgentTool, getBalanceTool } from '@0xgasless/agent-sdk';
// Get all pre-built tools
const tools = getAgentTools(sdk);
// Or use individual tools
const registerTool = registerAgentTool(sdk);
const balanceTool = getBalanceTool(sdk);
// Use with LangChain agent
const agent = new ChatOpenAI({ ... });
const chain = AgentExecutor.fromAgentAndTools({
agent,
tools,
});import { SessionKeyHelper } from '@0xgasless/agent-sdk';
import { parseUnits } from 'ethers';
// Generate session key with constraints
const sessionKey = SessionKeyHelper.generateSessionKey({
maxSpendPerTx: parseUnits('10', 6), // 10 USDT per tx
maxSpendPerDay: parseUnits('100', 6), // 100 USDT per day
validForSeconds: 7 * 24 * 60 * 60, // 7 days
whitelistedContracts: ['0x...'],
});
// Create wallet from session key
const sessionWallet = SessionKeyHelper.createWallet(sessionKey, provider);
// Validate before spending
const validation = SessionKeyHelper.validateTransaction(
sessionKey,
{ to: '0x...', value: parseUnits('5', 6) },
spentToday
);
if (!validation.valid) {
console.error('Transaction blocked:', validation.reason);
}import { FetchAIAgent } from '@0xgasless/agent-sdk';
const fetchAgent = new FetchAIAgent(sdk, {
apiKey: process.env.FETCHAI_API_KEY,
model: 'asi1-mini',
});
const result = await fetchAgent.query('Research DeFi trends on Avalanche');
console.log(result);| Variable | Required | Description |
|---|---|---|
PRIVATE_KEY |
Yes | Agent wallet private key |
RPC_URL |
No | RPC endpoint (defaults to Fuji) |
MOLTPAY_NETWORK |
No | Network override (avax-fuji or avax-mainnet) |
X402_FACILITATOR_URL |
No | Custom facilitator URL |
import {
fujiConfig,
mainnetConfig,
ERC8004_V2,
ERC8004_V2_MAINNET
} from '@0xgasless/agent-sdk';
// Testnet (Fuji)
const testnetSdk = new AgentSDK({
networks: fujiConfig.networks,
defaultNetwork: 'fuji',
signer: wallet,
});
// Mainnet
const mainnetSdk = new AgentSDK({
networks: mainnetConfig.networks,
defaultNetwork: 'mainnet',
signer: wallet,
});
// Contract addresses
console.log(ERC8004_V2); // Fuji addresses
console.log(ERC8004_V2_MAINNET); // Mainnet addressesimport { ERC8004Provider } from '@0xgasless/agent-sdk';
const provider = new ERC8004Provider(
'https://api.avax-test.network/ext/bc/C/rpc',
process.env.PRIVATE_KEY!,
'avax-fuji'
);
// Check registration status
const isRegistered = await provider.isRegistered();
if (!isRegistered) {
const agentId = await provider.register('https://myagent.com/metadata.json');
console.log('Registered with ID:', agentId);
}import { usePrivy, useWallets } from '@privy-io/react-auth';
import { AgentSDK, fujiConfig } from '@0xgasless/agent-sdk';
function AgentComponent() {
const { ready, authenticated } = usePrivy();
const { wallets } = useWallets();
const initSDK = async () => {
const wallet = wallets[0];
const provider = await wallet.getEthersProvider();
const signer = await provider.getSigner();
const sdk = new AgentSDK({
...fujiConfig,
signer,
});
return sdk;
};
}import { BrowserProvider } from 'ethers';
import { AgentSDK, fujiConfig } from '@0xgasless/agent-sdk';
async function connectMetaMask() {
const provider = new BrowserProvider(window.ethereum);
await provider.send('eth_requestAccounts', []);
const signer = await provider.getSigner();
const sdk = new AgentSDK({
...fujiConfig,
signer,
});
return sdk;
}This SDK is completely wallet-agnostic. Use any wallet:
| Wallet | Status | Example |
|---|---|---|
| ethers.js Wallet | β Supported | new Wallet(privateKey, provider) |
| Session Keys | β Supported | SessionKeyHelper.createWallet(...) |
| Privy | β Supported | wallet.getEthersProvider() |
| Dynamic.xyz | β Supported | primaryWallet.getWalletClient() |
| MetaMask | β Supported | BrowserProvider(window.ethereum) |
| Safe | β Supported | SafeWalletProvider |
git clone https://github.com/0xgasless/agent-sdk.git
cd agent-sdk
npm install
npm run build
npm run build:clinpm test# Build and link locally
npm run build:cli
node dist/cli/index.js --helpMIT - see LICENSE
- π Documentation
- π Issues
- π¦ Twitter
Built with β€οΈ by 0xGasless