npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thirdweb-dev/ai-sdk-provider

v0.1.4

Published

A [Vercel AI SDK](https://ai-sdk.dev/docs/introduction) provider that integrates thirdweb's blockchain AI capabilities into your applications. Build AI agents and chat UIs that can interact with smart contracts, execute transactions, and perform swaps dir

Readme

thirdweb AI SDK Provider

A Vercel AI SDK provider that integrates thirdweb's blockchain AI capabilities into your applications. Build AI agents and chat UIs that can interact with smart contracts, execute transactions, and perform swaps directly from AI responses.

Features

  • Blockchain-aware AI: AI models that understand and can interact with blockchain data
  • Transaction execution: Sign and execute transactions directly from AI responses
  • Token swaps: Perform token swaps through AI-generated actions
  • Transaction monitoring: Track transaction status and confirmations
  • Session continuity: Maintain conversation context across interactions
  • Type safety: Full TypeScript support with typed tool results
  • Streaming support: Real-time AI responses with reasoning steps

Installation

npm install @thirdweb-dev/ai-sdk-provider ai @ai-sdk/react

Usage

Server Setup (Next.js App Router)

Create an API route to handle AI chat requests:

// app/api/chat/route.ts
import { convertToModelMessages, streamText } from "ai";
import { createThirdwebAI } from "@thirdweb-dev/ai-sdk-provider";

// Allow streaming responses up to 5 minutes
export const maxDuration = 300;

const thirdwebAI = createThirdwebAI({
  secretKey: process.env.THIRDWEB_SECRET_KEY,
});

export async function POST(req: Request) {
  const { messages, sessionId } = await req.json();

  const result = streamText({
    model: thirdwebAI.chat({
      context: {
        session_id: sessionId, // session id for continuity
        chain_ids: [8453], // optional chain ids
        from: "0x...", // optional from address
        auto_execute_transactions: false, // optional, defaults to false
      },
    }),
    messages: convertToModelMessages(messages),
    tools: thirdwebAI.tools(), // optional, enables transaction and swap tools
  });

  return result.toUIMessageStreamResponse({
    sendReasoning: true, // optional, sends reasoning steps to client
    messageMetadata({ part }) {
      // record session id for continuity
      if (part.type === "finish-step") {
        return {
          session_id: part.response.id,
        };
      }
    },
  });
}

Client Setup (React)

Use the useChat hook with thirdweb message types:

"use client";

import { useState } from "react";
import { useChat, DefaultChatTransport } from "@ai-sdk/react";
import type { ThirdwebAiMessage } from "@thirdweb-dev/ai-sdk-provider";

export function Chat() {
  const [sessionId, setSessionId] = useState("");

  const { messages, sendMessage, addToolResult, status } =
    useChat<ThirdwebAiMessage>({
      transport: new DefaultChatTransport({ api: "/api/chat" }),
      onFinish: ({ message }) => {
        // save session id for continuity
        setSessionId(message.metadata?.session_id ?? "");
      },
    });

  const send = (message: string) => {
    sendMessage(
      { text: message },
      {
        body: {
          // send session id for continuity
          sessionId,
        },
      }
    );
  };

  return (
    <>
      {messages.map((message) => (
        <RenderMessage
          key={message.id}
          message={message}
          sessionId={sessionId}
          addToolResult={addToolResult}
          send={send}
        />
      ))}
      <ChatInputBox send={send} />
    </>
  );
}

Handling Tool Results

Render different message types and handle blockchain actions:

import { TransactionButton } from "thirdweb/react";
import { prepareTransaction } from "thirdweb";
import type { ThirdwebAiMessage } from "@thirdweb-dev/ai-sdk-provider";

export function RenderMessage(props: {
  message: ThirdwebAiMessage;
  sessionId: string;
  addToolResult: (toolResult: any) => void;
  send: (message: string) => void;
}) {
  const { message, sessionId, addToolResult, send } = props;

  return (
    <>
      {message.parts.map((part, i) => {
        switch (part.type) {
          case "text":
            return <div key={i}>{part.text}</div>;

          case "reasoning":
            return (
              <div key={i} className="reasoning">
                {part.text}
              </div>
            );

          case "tool-sign_transaction":
            // example of how to handle transaction confirmations
            const transactionData = part.input;
            return (
              <TransactionButton
                key={i}
                transaction={() =>
                  prepareTransaction({
                    client: THIRDWEB_CLIENT,
                    chain: defineChain(transactionData.chain_id),
                    to: transactionData.to,
                    data: transactionData.data,
                    value: transactionData.value,
                  })
                }
                onTransactionSent={(transaction) => {
                  // add the tool result to continue conversation
                  addToolResult({
                    tool: "sign_transaction",
                    toolCallId: part.toolCallId,
                    output: {
                      transaction_hash: transaction.transactionHash,
                      chain_id: transaction.chain.id,
                    },
                  });

                  // continue the conversation with tool result
                  send("");
                }}
                onError={(error) => {
                  send(`Transaction failed: ${error.message}`);
                }}
              >
                Execute Transaction
              </TransactionButton>
            );

          case "tool-sign_swap":
            return <SwapButton key={i} input={part.input} />;

          case "tool-monitor_transaction":
            return <TransactionMonitor key={i} input={part.input} />;

          default:
            return null;
        }
      })}
    </>
  );
}

Configuration

ThirdwebConfig

interface ThirdwebConfig {
  /** Base URL of the thirdweb API (defaults to https://api.thirdweb.com) */
  baseURL?: string;
  /** Project secret key for backend usage */
  secretKey?: string;
  /** Project client ID for frontend usage */
  clientId?: string;
  /** User wallet auth token (JWT) for executing transactions */
  walletAuthToken?: string;
}

ThirdwebSettings

interface ThirdwebSettings {
  context?: {
    /** Whether to automatically execute transactions (defaults to false) */
    auto_execute_transactions?: boolean;
    /** Default chain IDs for queries and transactions */
    chain_ids?: number[];
    /** From address to execute transactions from */
    from?: string;
    /** Session ID for conversation continuity */
    session_id?: string | null;
  };
}

Available Tools

The provider includes three built-in tools:

  • sign_transaction: Sign and execute blockchain transactions
  • sign_swap: Perform token swaps
  • monitor_transaction: Track transaction status and confirmations

Resources

License

Apache-2.0