Vity Toolkit
TelegramTwitterGithubRequest new tool
  • Introduction
    • Vity Toolkit
    • ๐Ÿš€Quick Start - Langchain
    • ๐Ÿš€Quick Start - Vercel AI
  • Features
    • Apps and Actions
    • How can I use Action directly?
    • Agent Authentication
    • Extensions
  • Tools
    • Superteam Earn
    • Solana Wallet
    • Reddit
    • Gibwork
    • Twitter
  • EXAMPLES
    • AI Bounty Finder
Powered by GitBook
On this page
  1. Introduction

Quick Start - Langchain

Transfer tokens on Solana with the help of Langchain and Vity Toolkit in less than 30 lines

PreviousVity ToolkitNextQuick Start - Vercel AI

Last updated 4 months ago

In this guide you'll learn how to implement and use Vity Toolkit with Langchain in just a few lines of code. For the purpose of this example, we'll create an assistant that can transfer 0.01 USDC to another wallet on the Solana mainnet-beta.

Transfer tokens to another wallet on Solana

In this example, we will use LangChain Agent to transfer 0.01 USDC to another wallet on the Solana mainnet-beta using Vity Toolkit.

1

Install the package.

npm install vity-toolkit langchain @langchain/openai
2

Initialize Vity Toolkit and Langchain.

import { ChatOpenAI } from "@langchain/openai";
import { Action, LangchainToolkit } from "vity-toolkit";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";

const llm = new ChatOpenAI({ model: "gpt-4o" });
const toolKit = new LangchainToolkit({
    userPrivateKey: "<private_key>",
});
3

Get the required tools.

const tools = toolKit.getTools({ actions: [Action.SOLANA_WALLET_TRANSFER, Action.SOLANA_WALLET_GET_BALANCE, Action.SOLANA_WALLET_GET_MY_PUBLIC_KEY] });

If you donโ€™t know which tool is exactly needed for your task, you can directly pass the App.SOLANA_WALLET app as a tool.

const tools = toolKit.getTools({ apps: [App.SOLANA_WALLET] });
4

Define the Agent.

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a helpful assistant"],
  ["placeholder", "{chat_history}"],
  ["human", "{input}"],
  ["placeholder", "{agent_scratchpad}"],
]);

const agent = await createOpenAIFunctionsAgent({
    llm,
    tools,
    prompt,
});

const agentExecutor = new AgentExecutor({ agent, tools, verbose: true });
5

Execute the Agent.

const response = await agentExecutor.invoke({ input: "Transfer 0.001 USDC to 8ueAQRiLExT7M9CNSkR11FDGbx2UyJqpSxCp1y43PWWs in mainnet" });
console.log(response);

๐Ÿš€
Logovity-toolkit/code-samples/agent/transfer_token.ts at main ยท apneduniya/vity-toolkitGitHub
Full code