An AI agent that processes natural language payment commands and executes blockchain transactions using ENS (Ethereum Name Service) resolution.
- ENS Resolution: Convert ENS names (like
alice.eth) to Ethereum addresses - Reverse Resolution: Convert addresses back to ENS names
- Caching: In-memory caching for improved performance
- Validation: Comprehensive input validation and error handling
- Network Support: Configurable for mainnet/testnet
- Security: Environment-based configuration, no hardcoded secrets
npm installCopy .env.example to .env and configure:
RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
NETWORK_ID=11155111
ENABLE_REVERSE_RESOLUTION=true
CACHE_TTL_SECONDS=300# Run the demo
node ens-resolver.js
# Run comprehensive tests
node tests/ens-resolver.test.jsconst ENSResolver = require('./ens-resolver');
const resolver = new ENSResolver();
// Resolve ENS name to address
const address = await resolver.resolve('vitalik.eth');
console.log(address); // 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
// Reverse resolve address to ENS name
const ensName = await resolver.reverseResolve('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
console.log(ensName); // vitalik.eth// Custom configuration
const resolver = new ENSResolver('https://eth-mainnet.alchemyapi.io/v2/YOUR-API-KEY', 1);
// Test connection
const connected = await resolver.testConnection();
// Cache management
resolver.clearCache();
const stats = resolver.getCacheStats();
// Validation
const isValid = resolver.validateENSName('alice.eth'); // trueens-pay-agent/
βββ ens-resolver.js # Core ENS resolution class
βββ tests/
β βββ ens-resolver.test.js # Comprehensive test suite
βββ .env # Environment configuration
βββ .gitignore # Git ignore rules
βββ package.json # NPM configuration
βββ README.md # This file
| Variable | Description | Default |
|---|---|---|
RPC_URL |
Ethereum RPC endpoint | Required |
NETWORK_ID |
Network ID (1=mainnet, 11155111=sepolia) | 1 |
CACHE_TTL_SECONDS |
Cache expiration time | 300 |
ENABLE_REVERSE_RESOLUTION |
Enable addressβname lookup | true |
The test suite includes:
- β ENS name validation
- β Caching mechanism
- β Error handling
- β Reverse resolution
- β Real network integration (optional)
# Run all tests
node tests/ens-resolver.test.js
# Test with real network (configure RPC_URL first)
RPC_URL=your_rpc_url node tests/ens-resolver.test.js- β No hardcoded API keys
- β Environment-based configuration
- β Input validation and sanitization
- β Proper error handling
- β No logging of sensitive data
- Secure ENS resolution
- Comprehensive validation
- Caching system
- Error handling
- Test suite
- Install OpenCog Hyperon MeTTa
- Create payment parsing rules
- Build JavaScript-MeTTa bridge
- Natural language intent parsing
- ERC-20 token handling
- Transaction creation
- Gas estimation
- Transaction monitoring
new ENSResolver(rpcUrl?, networkId?)resolve(ensName)- Resolve ENS name to addressreverseResolve(address)- Resolve address to ENS namevalidateENSName(name)- Validate ENS name formattestConnection()- Test provider connectionclearCache()- Clear resolution cachegetCacheStats()- Get cache statistics
-
RPC_URL not configured
Error: RPC_URL not configured. Please set RPC_URL in .env fileSolution: Configure your
.envfile with a valid RPC endpoint -
Network connection failed
Connection test failed: network timeoutSolution: Check your internet connection and RPC endpoint
-
Invalid ENS name
Invalid ENS name format: invalid-nameSolution: Ensure ENS names end with
.ethand contain only valid characters
- Focus on ENS resolution quality first
- Add comprehensive tests for new features
- Follow existing code style and patterns
- Update documentation for API changes
MIT License - see LICENSE file for details