Core Polkadot Asset Hub blockchain plugin for Eliza OS that provides essential services and actions for asset operations, transfers, and encrypted messaging on the Polkadot ecosystem.
The Polkadot Asset Hub plugin serves as a foundational component of Eliza OS, bridging Polkadot Asset Hub blockchain capabilities with the Eliza ecosystem. It provides crucial services for asset operations, transfers, balance management, encrypted messaging, and transaction history, enabling both automated and user-directed interactions with the Polkadot Asset Hub blockchain.
- Asset Transfers: Transfer both native DOT and assets (tokens) securely
- Balance Queries: Query balance for any address or asset
- Multi-Asset Support: Support for native DOT and custom assets via asset IDs
- Encrypted Memos: Optional encrypted memo messages attached to transfers
- Wallet Information: Retrieve wallet address and balance
- Transaction History: Complete transaction history with decrypted memos
- Address Validation: Validate Substrate addresses
- Balance Tracking: Real-time balance monitoring for multiple assets
- Secure Messaging: Send encrypted messages via zero-amount transfers
- Memo Encryption: End-to-end encrypted memo messages using recipient's public key
- Message Decryption: Automatic decryption of received encrypted memos
- Privacy Protection: Messages only readable by intended recipient
- Transaction History: Complete transfer history with memo decryption
- Subscan Integration: Integration with Subscan API for transaction data
- Memo Retrieval: Retrieve and decrypt memos from past transactions
- Transaction Tracking: Track sent and received transactions
- Wallet Management: Secure wallet key derivation and storage
- Private Key Protection: Secure private key handling with SR25519 encryption
- Key Derivation: Support for SR25519 keypair type
- Address Validation: SS58 format validation for addresses
- Memo Encryption: SR25519-based encryption for memo messages
- Public Key Encryption: Messages encrypted using recipient's public key
- Automatic Decryption: Seamless decryption of received messages
- Key Management: Secure keypair management and derivation
- Balance Validation: Pre-transfer balance checks
- Address Validation: Multi-level address format validation
- Transaction Limits: Configurable transaction validation
- Error Handling: Comprehensive error handling and reporting
npm install @chainsupport/eliza-polkadot-assethubConfigure the plugin by setting the following environment variables:
const polkadotAssetHubEnvSchema = {
ASSET_HUB_RPC_URL: string(optional), // RPC endpoint URL (defaults to public endpoint)
ASSET_HUB_PRIVATE_KEY: string(required), // Private key for wallet operations (hex format)
SUBSCAN_X_API_KEY: string(optional), // Subscan API key for transaction history
};- ASSET_HUB_PRIVATE_KEY: Your wallet's private key in hex format (0x...). This is required for all operations.
- ASSET_HUB_RPC_URL: Custom RPC endpoint URL. Defaults to public endpoint if not provided.
- SUBSCAN_X_API_KEY: Subscan API key for enhanced transaction history features. Optional but recommended.
import { polkadotAssetHubPlugin } from '@chainsupport/eliza-polkadot-assethub';
// Initialize the plugin
const runtime = await initializeRuntime({
plugins: [polkadotAssetHubPlugin],
settings: {
ASSET_HUB_PRIVATE_KEY: '0x...', // Your private key
ASSET_HUB_RPC_URL: 'https://rpc-asset-hub-polkadot.luckyfriday.io', // Optional
SUBSCAN_X_API_KEY: 'your-api-key', // Optional
},
});Main service for interacting with Polkadot Asset Hub blockchain.
const assetHubService = runtime.getService('Polkadot Asset Hub');
// Access chain client
const address = await assetHubService.chain.getMyAddress();
const balance = await assetHubService.chain.getUserBalance(address, assetId);
// Access Subscan API
const history = await assetHubService.subscanApi.addressTransferHistory(address);Low-level blockchain client for Substrate-based chains.
const chain = assetHubService.chain;
// Get wallet address
const address = await chain.getMyAddress();
// Query balance
const balance = await chain.getUserBalance(address, assetId); // assetId: null for DOT
// Transfer assets
const txHash = await chain.assetsTransferWithMemo(recipient, amount, assetId, memo);
// Send encrypted message
const txHash = await chain.sendMessage(recipient, message);API client for transaction history and memo retrieval.
const subscanApi = assetHubService.subscanApi;
// Get transfer history
const history = await subscanApi.addressTransferHistory(address);
// Decrypt memos
const decryptedHistory = await subscanApi.decryptTransfersMemo(history, cryptMessage);Transfers assets or native DOT between wallets with optional encrypted memo.
// Example usage
const result = await runtime.executeAction('TRANSFER_ASSETS_POLKADOT', {
assetId: 1984, // null for native DOT transfers
recipient: '14NL8ves2Ue59ZNy73GQT4bhFFNJm3M4eA6yoGvjgAPQMvXe',
amount: 1000,
memo: 'Hello, this is an encrypted message', // Optional
});Parameters:
assetId: Asset ID (number) ornullfor native DOT transfersrecipient: Recipient wallet address (string)amount: Transfer amount (number)memo: Optional encrypted memo message (string | null)
Common Asset IDs:
- USDT: 1984
- USDC: 1337
- Native DOT: null
Queries balance for any address or asset.
// Example usage - Query own DOT balance
const result = await runtime.executeAction('USER_ASSETS_BALANCE', {
address: null, // null for own address
assetId: null, // null for native DOT
});
// Example usage - Query user's asset balance
const result = await runtime.executeAction('USER_ASSETS_BALANCE', {
address: '14NL8ves2Ue59ZNy73GQT4bhFFNJm3M4eA6yoGvjgAPQMvXe',
assetId: 1984, // USDT
});Parameters:
address: Address to query (string | null) - null for own addressassetId: Asset ID (number | null) - null for native DOT
Sends an encrypted message to another user via zero-amount transfer.
// Example usage
const result = await runtime.executeAction('SEND_MESSAGE', {
recipient: '14NL8ves2Ue59ZNy73GQT4bhFFNJm3M4eA6yoGvjgAPQMvXe',
message: 'Hello, this is a private message',
});Parameters:
recipient: Recipient wallet address (string)message: Message content to encrypt and send (string)
Retrieves complete transaction history with decrypted memos.
// Example usage
const result = await runtime.executeAction('MY_WALLET_HISTORY', {});Returns:
- Complete transaction history with decrypted memos
- Includes sender, recipient, amount, memo, timestamp, and transaction ID
Retrieves current wallet information including address and balance.
// Example usage
const result = await runtime.executeAction('GET_MY_WALLET_INFO', {});Returns:
- Wallet address
- Native DOT balance
-
RPC Optimization
- Use reliable RPC endpoints
- Implement connection pooling
- Monitor RPC usage and rate limits
-
Cache Management
- Cache balance queries
- Cache transaction history
- Configure appropriate TTL settings
-
Transaction Management
- Batch operations when possible
- Implement retry strategies
- Monitor transaction success rates
- Node.js 16.x or higher
- TypeScript 5.x or higher
- Minimum 4GB RAM recommended
- Stable internet connection
- Access to Polkadot Asset Hub RPC endpoint
@elizaos/core: Eliza OS core framework@polkadot/api: Polkadot API client@polkadot/keyring: Keyring for key management@polkadot/util-crypto: Cryptographic utilities
@eliza-dot-aes/sr25519-aes: SR25519 encryption for memos@eliza-dot-aes/common: Common encryption utilities
- Wallet Connection Failures
Error: Failed to start Polkadot Asset Hub serviceSolutions:
- Verify RPC endpoint is accessible
- Check private key format (must start with 0x)
- Ensure proper network selection
- Verify ASSET_HUB_PRIVATE_KEY is set correctly
- Transaction Errors
Error: Insufficient balanceSolutions:
- Check account balance before transfer
- Verify amount is within available balance
- Ensure sufficient balance for transaction fees
- Check asset ID is correct
- Address Validation Errors
Error: Invalid addressSolutions:
- Verify address format (SS58 encoding)
- Check address is for Polkadot network (SS58 format 0)
- Ensure address is not empty or null
- Subscan API Errors
Error: Failed to get transaction historySolutions:
- Verify SUBSCAN_X_API_KEY is set correctly
- Check API key has proper permissions
- Ensure network connectivity
- Verify Subscan API service status
- Encryption Errors
Error: Failed to encrypt/decrypt memoSolutions:
- Verify recipient address is valid
- Check encryption service is initialized
- Ensure proper keypair type (SR25519)
- Verify message is not null or empty
-
Environment Variables
- Store private keys in secure environment variables
- Never commit private keys to version control
- Use .env.example for non-sensitive defaults
- Rotate API keys regularly
-
Private Key Management
- Use secure key derivation
- Never expose private keys in logs
- Implement proper key storage
- Use hardware wallets for production
-
Transaction Limits
- Set maximum transaction amounts
- Implement daily transfer limits
- Configure per-asset restrictions
- Monitor unusual transaction patterns
-
Monitoring
- Track failed transaction attempts
- Monitor balance changes
- Log security-relevant events
- Set up alerts for suspicious activity
-
Encryption
- Always use encrypted memos for sensitive data
- Verify recipient addresses before sending
- Test encryption/decryption in development
- Keep encryption libraries updated
Main service class for Polkadot Asset Hub operations.
Methods:
start(runtime): Initialize the servicestop(): Clean up resourceschain: Access SubstrateChain clientsubscanApi: Access SubscanApi client
Blockchain client for Substrate-based chains.
Key Methods:
getMyAddress(): Get wallet addressgetUserBalance(address, assetId): Query balanceassetsTransferWithMemo(to, amount, assetId, memo): Transfer assetstransferWithMemo(to, amount, memo): Transfer native DOTsendMessage(to, message): Send encrypted messagegetTransferMemo(txHash): Retrieve and decrypt memo from transaction
API client for transaction history.
Key Methods:
addressTransferHistory(address): Get transfer historydecryptTransfersMemo(transfers, cryptMessage): Decrypt memosgetTransferByHash(hash): Get transfer by transaction hash
// Transfer USDT with encrypted memo
const result = await runtime.executeAction('TRANSFER_ASSETS_POLKADOT', {
assetId: 1984, // USDT
recipient: '14NL8ves2Ue59ZNy73GQT4bhFFNJm3M4eA6yoGvjgAPQMvXe',
amount: 1000,
memo: 'Payment for services rendered',
});// Query own DOT balance
const result = await runtime.executeAction('USER_ASSETS_BALANCE', {
address: null,
assetId: null,
});// Send private message
const result = await runtime.executeAction('SEND_MESSAGE', {
recipient: '14NL8ves2Ue59ZNy73GQT4bhFFNJm3M4eA6yoGvjgAPQMvXe',
message: 'This message is encrypted and only the recipient can read it',
});For issues and feature requests, please:
- Check the troubleshooting guide above
- Review existing GitHub issues
- Submit a new issue with:
- System information
- Error logs
- Steps to reproduce
- Transaction IDs (if applicable)
- Network information (mainnet/testnet)
Licensed under the Apache License, Version 2.0. See LICENSE file for details.
Contributions are welcome! Please ensure:
- Code follows project style guidelines
- All tests pass
- Documentation is updated
- Security best practices are followed
- Polkadot ecosystem for blockchain infrastructure
- Subscan for transaction history API
- Eliza OS team for the framework
This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.