onchain-assistant-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.1.28 • Public • Published

OnChain Assistant SDK

An AI-powered blockchain interaction SDK for the browser, leveraging OpenAI's function calling and thirdweb's wallet connectors.

Features

  • 🧠 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

Installation

npm install onchain-assistant-sdk thirdweb

Requirements

  • OpenAI API key
  • thirdweb SDK v5
  • A browser environment

Quick Start

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);
});

React Integration Example

See the examples/react-integration.js file for a complete React component example that shows how to integrate the SDK with a chat interface.

Available Tools

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

Documentation

For more detailed documentation, see the SDK-README.md file.

License

ISC

Package Sidebar

Install

npm i onchain-assistant-sdk

Weekly Downloads

63

Version

0.1.28

License

ISC

Unpacked Size

245 kB

Total Files

107

Last publish

Collaborators

  • lootse