Overview
The Arcana x402 Agent Marketplace uses three core smart contracts deployed on Base Sepolia:- PolicyVault - Manages agent spending policies and daily limits
- Escrow - Handles USDC payment escrow for user queries
- AgentRegistry - Registers agents and links to the escrow system
Prerequisites
Before deploying contracts, ensure you have:- Base Sepolia ETH for gas fees (get from Base Sepolia faucet)
- Private key of wallet with ETH
- Agent wallet address to set as the authorized agent
- Node.js 18+ installed
Deployment Script
The repository includes a Node.js deployment script at:- Compiles Solidity contracts using
solc - Deploys PolicyVault, Escrow, and AgentRegistry
- Links contracts together (sets allowlists and references)
- Outputs deployed addresses for your
.envfile
Configuration
Running the Deployment
Save deployed addresses
The script outputs a JSON result with all deployed addresses:Copy these addresses to your
backend/.env:Verify on BaseScan
Visit BaseScan Sepolia and search for your contract addresses to verify deployment.
Contract Details
PolicyVault
Purpose: Manages per-agent spending policies and daily limits. Constructor Parameters:agentAddress- The wallet address authorized as an agentdailyLimit- Maximum spending per day (in Wei or Ether units)
setAllowlist(address, bool)- Authorize/revoke addresses (e.g., Escrow contract)checkLimit(address, uint256)- Verify if spending is within daily limit
Escrow
Purpose: Holds USDC payments from users until query completion. Constructor Parameters:usdcAddress- USDC token contract address on Base Sepolia
deposit(uint256 amount)- User deposits USDC into escrowrelease(address to, uint256 amount)- Release funds to recipientsetAgentRegistry(address)- Link to AgentRegistry contract
AgentRegistry
Purpose: Registers agents and maintains escrow linkage. Key Functions:setEscrowContract(address)- Link to Escrow contractregisterAgent(...)- Register new agent (if implemented)
Contract Linking
The deployment script automatically links contracts:Contract linking is essential for the system to function. The deployment script handles this automatically.
Foundry Alternative
If you prefer Foundry for deployment, the repository includes Foundry configuration:Verification on BaseScan
To verify your contracts on BaseScan Sepolia:Get BaseScan API key
Sign up at BaseScan and create an API key.
Troubleshooting
Insufficient funds for gas
Error:insufficient funds for gas * price + value
Solution: Add more Base Sepolia ETH to your deployer wallet.
Invalid AGENT_ADDRESS
Error:Missing or invalid AGENT_ADDRESS
Solution: Ensure AGENT_ADDRESS in .env is a valid Ethereum address starting with 0x.
Wrong chain ID
Warning:Expected chain ID 84532, got 1
Solution: Verify CHAIN_RPC_URL points to Base Sepolia (https://sepolia.base.org).
Compilation errors
Error:Solidity compile error: ...
Solution: Ensure Solidity contracts in src/ are valid and match the expected version (^0.8.20).
Nonce too low
Error:nonce has already been used
Solution: The script manages nonces automatically. If you see this error, wait a few seconds and retry, or clear pending transactions from your wallet.
Post-Deployment
After successful deployment:- Update
.envwith contract addresses - Restart backend to load new configuration
- Test deposits through the frontend
- Verify transactions on BaseScan
- Monitor gas costs for optimization
Security Considerations
Production Hardening
Before deploying to production (mainnet):- Audit smart contracts with a professional security firm
- Test thoroughly on testnet with realistic scenarios
- Implement multi-sig for contract ownership
- Set conservative limits initially
- Monitor contract activity with alerts
- Prepare upgrade path if using proxy patterns
- Document emergency procedures
Next Steps
- Complete your Environment Variables configuration
- Start Local Development with deployed contracts
- Review the Architecture Overview to understand contract interactions