Skip to content

hebuildapps/Agentic-ENS-Paybot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ENS Pay Agent

An AI agent that processes natural language payment commands and executes blockchain transactions using ENS (Ethereum Name Service) resolution.

🎯 Features

  • 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

πŸš€ Quick Start

1. Install Dependencies

npm install

2. Configure Environment

Copy .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

3. Test ENS Resolution

# Run the demo
node ens-resolver.js

# Run comprehensive tests
node tests/ens-resolver.test.js

πŸ“– Usage

Basic ENS Resolution

const 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

Advanced Usage

// 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'); // true

πŸ—οΈ Project Structure

ens-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

βš™οΈ Configuration

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

πŸ§ͺ Testing

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

πŸ›‘οΈ Security

  • βœ… No hardcoded API keys
  • βœ… Environment-based configuration
  • βœ… Input validation and sanitization
  • βœ… Proper error handling
  • βœ… No logging of sensitive data

πŸ”„ Development Phases

βœ… Phase 1: ENS Foundation (COMPLETE)

  • Secure ENS resolution
  • Comprehensive validation
  • Caching system
  • Error handling
  • Test suite

πŸ“‹ Phase 2: MeTTa Integration (NEXT)

  • Install OpenCog Hyperon MeTTa
  • Create payment parsing rules
  • Build JavaScript-MeTTa bridge
  • Natural language intent parsing

🎯 Phase 3: Payment System

  • ERC-20 token handling
  • Transaction creation
  • Gas estimation
  • Transaction monitoring

πŸ“ API Reference

ENSResolver Class

Constructor

new ENSResolver(rpcUrl?, networkId?)

Methods

  • resolve(ensName) - Resolve ENS name to address
  • reverseResolve(address) - Resolve address to ENS name
  • validateENSName(name) - Validate ENS name format
  • testConnection() - Test provider connection
  • clearCache() - Clear resolution cache
  • getCacheStats() - Get cache statistics

πŸ› Troubleshooting

Common Issues

  1. RPC_URL not configured

    Error: RPC_URL not configured. Please set RPC_URL in .env file
    

    Solution: Configure your .env file with a valid RPC endpoint

  2. Network connection failed

    Connection test failed: network timeout
    

    Solution: Check your internet connection and RPC endpoint

  3. Invalid ENS name

    Invalid ENS name format: invalid-name
    

    Solution: Ensure ENS names end with .eth and contain only valid characters

🀝 Contributing

  1. Focus on ENS resolution quality first
  2. Add comprehensive tests for new features
  3. Follow existing code style and patterns
  4. Update documentation for API changes

πŸ“„ License

MIT License - see LICENSE file for details

About

Building an AI Agent on Agentverse for straight up paying a friend's ens name on just a query.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published