neon-onchain-ai
v1.0.0
Published
An AI-powered blockchain agent that can interact with EVM blockchains
Maintainers
Readme
Neon Onchain AI
An AI-powered blockchain agent that can interact with any EVM blockchain. Built with OpenAI's Assistant API and viem.
Installation
npm install neon-onchain-aiQuick Start
import { BlockchainAgent } from 'neon-onchain-ai';
function MyApp() {
return (
<BlockchainAgent
openaiApiKey="your-openai-key-here"
/>
);
}Using with MetaMask and Wagmi
import { useAccount, useNetwork } from 'wagmi';
import { useOnchainAgent } from 'neon-onchain-ai';
function BlockchainAssistant() {
const { address } = useAccount();
const { chain } = useNetwork();
const { messages, sendMessage, isLoading } = useOnchainAgent({
openaiApiKey: "your-openai-key-here",
account: address ? {
address: address as `0x${string}`,
type: 'json-rpc'
} : undefined,
chain: chain
});
// Your custom UI implementation
}Direct SDK Usage
import { OnchainAgentSDK } from 'neon-onchain-ai';
import { polygon } from 'viem/chains';
async function main() {
const agent = new OnchainAgentSDK({
openaiApiKey: "your-openai-key",
chain: polygon,
// Account will come from MetaMask or private key
});
await agent.initialize();
const response = await agent.sendMessage("Deploy an ERC20 token");
console.log(response.value);
}Direct Blockchain Access
You can directly access the blockchain clients for operations:
import { OnchainAgentSDK } from 'neon-onchain-ai';
import { polygon } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
// Create the SDK
const account = privateKeyToAccount('0x...');
const sdk = new OnchainAgentSDK({
openaiApiKey: "your-openai-key",
chain: polygon,
account
});
// Get the clients for direct access
const publicClient = sdk.getPublicClient();
const walletClient = sdk.getWalletClient();
// Example: Check balance
async function checkBalance(address) {
const balance = await publicClient.getBalance({ address });
console.log(`Balance: ${balance} wei`);
}
// Example: Send a transaction
async function sendTransaction(to, value) {
// Convert ETH to wei (assuming value is in ETH)
const valueInWei = BigInt(Math.floor(Number(value) * 1e18));
const hash = await walletClient.sendTransaction({
to,
value: valueInWei
});
console.log(`Transaction hash: ${hash}`);
}AI Assistant Capabilities
The AI assistant can handle the following blockchain operations through natural language:
Read Operations:
- Get ETH balance of an address
- Get ERC20 token balance
- Get wallet address
- Read data from contracts
- Get transaction receipts
Write Operations:
- Deploy ERC20 tokens
- Send transactions
- Write to contracts
- Approve token allowances
- Create liquidity pools
Simply use natural language to request these operations:
// Example operations through natural language
await sdk.sendMessage("What's my current ETH balance?");
await sdk.sendMessage("Deploy an ERC20 token named 'MyToken' with symbol 'MTK'");
await sdk.sendMessage("Send 0.1 ETH to 0x123...");Documentation
For detailed usage instructions and examples, see the full documentation.
Features
- AI Assistant powered by OpenAI's Assistant API
- Direct blockchain interactions through Viem
- Direct access to all blockchain tools
- React integration with custom hooks and components
- Support for:
- Any EVM-compatible chain
- MetaMask and other wallet providers
- Private key authentication
- ERC20 token deployments and interactions
- Contract reading and writing
- Balance checking
- Transaction management
- Uniswap V3 pool creation
License
ISC
