🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

onchain-assistant-sdk

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onchain-assistant-sdk

AI-powered blockchain interactions for the browser

0.1.28
latest
npm
Version published
Weekly downloads
84
-84.59%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

blockchain

FAQs

Package last updated on 24 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts