ATP Plugin
The ATP Plugin enables your agent to interact with IQβs Agent Tokenization Platform. It provides functionality for:
Buying, selling, and managing AI agent tokens using IQ as the base currency Viewing agent performance metrics and token statistics Managing token holdings and checking position values
Installation
-
Install the required packages:
Terminal window npm i @iqai/agent @iqai/plugin-atpTerminal window pnpm add @iqai/agent @iqai/plugin-atpTerminal window yarn add @iqai/agent @iqai/plugin-atp -
Create a .env file with the required configuration:
Terminal window WALLET_PRIVATE_KEY=your-wallet-private-keyNever commit your
.env
file or share your private key. Anyone with access to your private key can control your wallet and funds. Make sure to:- Add
.env
to your.gitignore
file - Never share your private key in any form
- Use a dedicated development wallet with limited funds
- Add
Basic Setup
Hereβs a complete example of setting up an agent with the ATP plugin:
import { AgentBuilder, ModelProviderName } from "@iqai/agent";import { createATPPlugin } from "@iqai/plugin-atp";
async function main() { // Initialize ATP plugin const atpPlugin = await createATPPlugin({ walletPrivateKey: process.env.WALLET_PRIVATE_KEY, });
// Create agent with plugin const agent = new AgentBuilder() .withClient(DirectClient) .withModelProvider( ModelProviderName.OPENAI, process.env.OPENAI_API_KEY ) .withPlugin(bootstrapPlugin) .withPlugin(atpPlugin) .build();
await agent.start();}
main().catch(console.error);
Available Operations
- Agent Statistics: View performance metrics and token statistics
- Portfolio Management: Monitor holdings and position values
- Trading Operations: Buy/sell agent tokens using IQ
- Agents list: View a list of available agents
Usage Examples
Operation | Example Query |
---|---|
Check Stats | Show me stats for agent 0x1234...5678 |
View Portfolio | Show my ATP holdings |
Buy Tokens | Buy 1000 IQ worth of agent 0x1234...5678 |
Sell Tokens | Sell 50 tokens of agent 0x1234...5678 |
List Agents | Show me top agents on atp |
Configuration Options
The ATP plugin accepts the following configuration parameters:
interface ATPPluginConfig { walletPrivateKey: string; // Private key for transactions}
Error Handling
Always implement proper error handling when using the plugin:
try { const atpPlugin = await createATPPlugin({ walletPrivateKey: process.env.WALLET_PRIVATE_KEY, });} catch (error) { console.error('Failed to initialize ATP plugin:', error);}
Best Practices
- β Token Validation: Verify agent addresses before transactions
- β Amount Verification: Double-check token amounts and IQ values
- β Transaction Monitoring: Track transaction status and confirmations
- β Balance Management: Ensure sufficient IQ balance for purchases
Common Issues and Troubleshooting
- Invalid Agent Address: Ensure youβre using the correct agent token contract address
- Insufficient IQ Balance: Verify you have enough IQ tokens for purchases
- Transaction Failures: Check transaction parameters and network status
- Token Approval: Ensure proper token approvals before selling