mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-21 07:36:45 +00:00
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Tool } from "langchain/tools";
|
|
import { SolanaAgentKit } from "../../agent";
|
|
|
|
export class SolanaDeployTokenTool extends Tool {
|
|
name = "solana_deploy_token";
|
|
description = `Deploy a new token on Solana blockchain.
|
|
|
|
Inputs (input is a JSON string):
|
|
name: string, eg "My Token" (required)
|
|
uri: string, eg "https://example.com/token.json" (required)
|
|
symbol: string, eg "MTK" (required)
|
|
decimals?: number, eg 9 (optional, defaults to 9)
|
|
initialSupply?: number, eg 1000000 (optional)`;
|
|
|
|
constructor(private solanaKit: SolanaAgentKit) {
|
|
super();
|
|
}
|
|
|
|
protected async _call(input: string): Promise<string> {
|
|
try {
|
|
const parsedInput = JSON.parse(input);
|
|
|
|
const result = await this.solanaKit.deployToken(
|
|
parsedInput.name,
|
|
parsedInput.uri,
|
|
parsedInput.symbol,
|
|
parsedInput.decimals,
|
|
parsedInput.initialSupply,
|
|
);
|
|
|
|
return JSON.stringify({
|
|
status: "success",
|
|
message: "Token deployed successfully",
|
|
mintAddress: result.mint.toString(),
|
|
decimals: parsedInput.decimals || 9,
|
|
});
|
|
} catch (error: any) {
|
|
return JSON.stringify({
|
|
status: "error",
|
|
message: error.message,
|
|
code: error.code || "UNKNOWN_ERROR",
|
|
});
|
|
}
|
|
}
|
|
}
|