A simple template for creating agents that use Brewit delegation to distribute tokens. This example shows how to build a faucet service that allows users to claim tokens from delegated accounts.
- Distributes tokens: Users can claim native tokens (ETH) and ERC-20 tokens
- Uses delegation: The agent has delegated access to other accounts' tokens
- Simple API: Clean REST endpoints for claiming tokens
- Account abstraction: Uses Brewit (Safe powered) accounts for enhanced security
- Install dependencies:
yarn install- Set up environment:
cp env.example .env
# Edit .env and add your private key- Start the service:
yarn devThe agent creates a main account and gets delegated access to tokens from other accounts.
When a user requests tokens:
- Native tokens are sent directly from the main account
- ERC-20 tokens are sent from delegated accounts
- All transactions are signed and broadcast automatically
Claim tokens:
curl -X POST http://localhost:8002/claim \
-H "Content-Type: application/json" \
-d '{
"tokens": ["0x1234..."],
"toAddress": "0x5678..."
}'Get agent info:
curl http://localhost:8002/infoHealth check:
curl http://localhost:8002/healthPORT=8002 # Server port
NODE_ENV=development # Environment
LOG_LEVEL=info # Logging level
AGENT_PRIVATE_KEY=0x... # Your private key (required)Edit src/config.json to set up your agent's private key and salt:
{
"privateKey": "your_private_key_here",
"salt": "your_session_salt_here"
}faucet/
├── src/
│ ├── index.ts # Main server
│ ├── routes/ # API routes
│ │ ├── faucet.ts # Token claiming
│ │ ├── health.ts # Health check
│ │ └── info.ts # Agent info
│ ├── executer/ # Core logic
│ │ ├── index.ts # Main execution
│ │ └── utils/ # Utilities
│ ├── middleware/ # Express middleware
│ ├── types/ # TypeScript types
│ ├── utils.ts # Helper functions
│ └── config.json # Agent config
├── package.json
└── README.md
Edit the amounts in src/executer/index.ts:
// Native token amount
value: parseEther('0.1')
// ERC-20 token amount
amount: '0.001'Add new token addresses to the tokens array in your API calls.
Update validation rules in the route handlers to add rate limiting, address validation, etc.
Update the chain ID in the execution functions (currently set to 10143).
This template uses Brewit's delegation system to access tokens from other accounts without needing their private keys.
Uses smart contract wallets (ERC-4337) for enhanced security and functionality.
The agent creates delegated accounts that can spend tokens on behalf of the main account.
Start development server:
yarn devBuild for production:
yarn build
yarn startRun tests:
yarn testMIT