mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-05 07:36:45 +00:00
feat: Enhance Solana tools with action-based architecture
- Introduced action system for Solana tools, allowing for better modularity and maintainability. - Updated SolanaBalanceTool, SolanaTransferTool, SolanaDeployTokenTool, SolanaDeployCollectionTool, SolanaMintNFTTool, SolanaTradeTool, and SolanaRequestFundsTool to utilize action handlers. - Added new action exports in index.ts for better organization and accessibility.
This commit is contained in:
88
src/actions/mintNFT.ts
Normal file
88
src/actions/mintNFT.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
|
||||
const mintNFTAction: Action = {
|
||||
name: "solana_mint_nft",
|
||||
similes: [
|
||||
"mint nft",
|
||||
"create nft",
|
||||
"mint token",
|
||||
"create token",
|
||||
"add nft to collection"
|
||||
],
|
||||
description: `Mint a new NFT in a collection on Solana blockchain.`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
collectionMint: "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w",
|
||||
name: "My NFT",
|
||||
uri: "https://example.com/nft.json"
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "NFT minted successfully",
|
||||
mintAddress: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN",
|
||||
metadata: {
|
||||
name: "My NFT",
|
||||
uri: "https://example.com/nft.json"
|
||||
},
|
||||
recipient: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN"
|
||||
},
|
||||
explanation: "Mint an NFT to the default wallet"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
input: {
|
||||
collectionMint: "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w",
|
||||
name: "Gift NFT",
|
||||
uri: "https://example.com/gift.json",
|
||||
recipient: "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u"
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "NFT minted successfully",
|
||||
mintAddress: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM",
|
||||
metadata: {
|
||||
name: "Gift NFT",
|
||||
uri: "https://example.com/gift.json"
|
||||
},
|
||||
recipient: "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u"
|
||||
},
|
||||
explanation: "Mint an NFT to a specific recipient"
|
||||
}
|
||||
]
|
||||
],
|
||||
schema: z.object({
|
||||
collectionMint: z.string().min(32, "Invalid collection mint address"),
|
||||
name: z.string().min(1, "Name is required"),
|
||||
uri: z.string().url("URI must be a valid URL"),
|
||||
recipient: z.string().min(32, "Invalid recipient address").optional()
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
const result = await agent.mintNFT(
|
||||
new PublicKey(input.collectionMint),
|
||||
{
|
||||
name: input.name,
|
||||
uri: input.uri,
|
||||
},
|
||||
input.recipient ? new PublicKey(input.recipient) : agent.wallet_address
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "NFT minted successfully",
|
||||
mintAddress: result.mint.toString(),
|
||||
metadata: {
|
||||
name: input.name,
|
||||
uri: input.uri
|
||||
},
|
||||
recipient: input.recipient || result.mint.toString()
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default mintNFTAction;
|
||||
Reference in New Issue
Block a user