An AI-powered blockchain interaction SDK for the browser, leveraging OpenAI's function calling and thirdweb's wallet connectors.
- 🧠 Natural language processing of user queries
- 🔗 Seamless blockchain interactions via thirdweb
- 🛠️ Smart contract read/write operations
- 💰 Token balances and transfers
- 📊 Real-time cryptocurrency market data via CoinGecko
- 📈 Token price lookups and market statistics
- 🔍 Token search functionality
- 🔐 Secure wallet integration (no private keys required)
- 📝 Advanced transaction management
- 📘 Full TypeScript support with declaration files
npm install onchain-assistant-sdk thirdweb
- OpenAI API key
- thirdweb SDK v5
- A browser environment
import { createOnChainAssistant } from 'onchain-assistant-sdk';
import { createThirdwebClient } from 'thirdweb';
import { useActiveAccount, useActiveWallet } from 'thirdweb/react';
// In your React component
function MyComponent() {
// Get wallet from thirdweb hooks
const account = useActiveAccount();
const wallet = useActiveWallet();
const address = account?.address;
// Initialize thirdweb client
const thirdwebClient = createThirdwebClient({
clientId: "your-thirdweb-client-id"
});
// Initialize the OnChain Assistant SDK with wallet from hooks
const assistant = createOnChainAssistant({
openAIApiKey: 'your-openai-api-key',
thirdwebClient,
connectedWallet: wallet, // Pass the wallet from hooks
connectedAddress: address, // Pass the address from hooks
coinGeckoApiKey: 'your-coingecko-api-key', // Optional
enableMarketData: true, // Enable market data tools (default: true)
aiOptions: {
model: 'gpt-4o-mini',
temperature: 0.7
}
});
// Rest of your component...
}
// Process a user query
const handleUserQuery = async (userInput) => {
if (!assistant.isWalletConnected()) {
console.log('Please connect your wallet first');
return;
}
try {
const result = await assistant.processUserQuery(userInput);
console.log('AI Response:', result.response);
if (result.transaction) {
console.log('Transaction:', result.transaction);
}
} catch (error) {
console.error('Error:', error);
}
};
// Subscribe to events
assistant.subscribe('transaction:succeeded', (data) => {
console.log('Transaction successful:', data);
});
See the examples/react-integration.js
file for a complete React component example that shows how to integrate the SDK with a chat interface.
The SDK currently supports these blockchain operations through natural language:
- Getting wallet balances (native tokens)
- Getting token balances (ERC20)
- Reading smart contract data
- Writing to smart contracts
- Viewing transaction information
For more detailed documentation, see the SDK-README.md
file.
ISC