0.2.0 âĸ Published 7 months ago
@iqai/plugin-near v0.2.0
đ Plugin NEAR
A NEAR Protocol integration plugin enabling smart contract interaction, transaction handling, and event listening on the NEAR blockchain.
đ Overview
This plugin provides seamless integration with the NEAR Protocol blockchain.
- â Execute contract methods and transactions on NEAR blockchain
- â Listen to and respond to contract events
- â View contract data and account information
- â Handle custom logic through event listeners
đ Blockchain Event-Driven Workflow
The plugin enables an "AI in the loop" workflow:
- đ Smart contract transaction triggers an event and pauses execution
- đ¤ Agent detects the event and performs AI computation
- âŠī¸ Agent returns results via blockchain transaction
- â Original smart contract resumes with the AI-provided data
đ Installation
Install the plugin using pnpm:
pnpm add @iqai/plugin-near
After installation, you can use the plugin like this:
import createNearPlugin from "@iqai/plugin-near";
const nearPlugin = await createNearPlugin(options);
const agent = new AgentBuilder()
...
.withPlugin(nearPlugin)
â Configuration
đ§ Variable Name | đ Description |
---|---|
NEAR_ACCOUNT_ID | Your NEAR account ID for authentication đ |
NEAR_PRIVATE_KEY | Private key for your NEAR account đ |
đ Usage
import createNearPlugin from "@iqai/plugin-near";
// Initialize the plugin
const nearPlugin = await createNearPlugin({
accountId: process.env.NEAR_ACCOUNT_ID,
accountKey: process.env.NEAR_PRIVATE_KEY,
listeners: [
{
eventName: "run_agent",
contractId: "your-contract.testnet",
responseMethodName: "agent_response",
handler: async (payload, { account }) => {
// Custom event handling logic
return "result";
},
}
],
networkConfig: {
networkId: "testnet", // or "mainnet"
nodeUrl: "https://test.rpc.fastnear.com",
},
});
đ Response Format
Responses from the NEAR plugin typically include:
- â Transaction status (Success/Failure)
- đ Transaction hash when applicable
- đ Formatted response data from contract calls
- đˇ Account information when relevant
â Error Handling
The plugin handles common NEAR-related errors:
- đ¨ Invalid contract calls or method names
- đ¸ Insufficient account balance for transactions
- đ Authentication issues with account credentials
- đ Network connectivity problems with NEAR RPC
- đĢ Contract execution errors returned by smart contracts