Skip to main content
Glama

transfer_erc1155

Transfer ERC1155 tokens to a specified wallet address by signing a transaction with the owner's private key. Supports both fungible and non-fungible tokens across multiple networks, including BSC, Ethereum, and Base.

Instructions

Transfer ERC1155 tokens to another address. ERC1155 is a multi-token standard that can represent both fungible and non-fungible tokens in a single contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe quantity of tokens to send (e.g., '1' for a single NFT or '10' for 10 fungible tokens)
networkNoNetwork name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet.bsc
privateKeyNoPrivate key of the token owner account in hex format (with or without 0x prefix). SECURITY: This is used only for transaction signing and is not stored.0x5a2b7e4d9c8f1a3e6b0d2c5f4e3d2a1b0c9f8e7d6a5b4c3d2e1f0a9b8c7d6e5f4
toAddressYesThe recipient wallet address that will receive the tokens
tokenAddressYesThe contract address of the ERC1155 token collection (e.g., '0x76BE3b62873462d2142405439777e971754E8E77')
tokenIdYesThe ID of the specific token to transfer (e.g., '1234')

Implementation Reference

  • The handler function that executes the logic for the 'transfer_erc1155' tool by invoking the transfer service and formatting the response.
    async ({ privateKey, tokenAddress, tokenId, amount, toAddress, network }) => { try { const result = await services.transferERC1155( tokenAddress as Address, toAddress as Address, BigInt(tokenId), amount, privateKey, network ) return mcpToolRes.success({ success: true, txHash: result.txHash, network, contract: tokenAddress, tokenId: result.tokenId, amount: result.amount, recipient: toAddress }) } catch (error) { return mcpToolRes.error(error, "transferring ERC1155 tokens") } }
  • Input schema using Zod for validating parameters of the 'transfer_erc1155' tool: privateKey, tokenAddress, tokenId, amount, toAddress, network.
    { privateKey: z .string() .describe( "Private key of the token owner account in hex format (with or without 0x prefix). SECURITY: This is used only for transaction signing and is not stored." ) .default(process.env.PRIVATE_KEY as string), tokenAddress: z .string() .describe( "The contract address of the ERC1155 token collection (e.g., '0x76BE3b62873462d2142405439777e971754E8E77')" ), tokenId: z .string() .describe("The ID of the specific token to transfer (e.g., '1234')"), amount: z .string() .describe( "The quantity of tokens to send (e.g., '1' for a single NFT or '10' for 10 fungible tokens)" ), toAddress: z .string() .describe("The recipient wallet address that will receive the tokens"), network: defaultNetworkParam },
  • Registers the 'transfer_erc1155' tool on the MCP server with description, input schema, and handler function.
    server.tool( "transfer_erc1155", "Transfer ERC1155 tokens to another address. ERC1155 is a multi-token standard that can represent both fungible and non-fungible tokens in a single contract.", { privateKey: z .string() .describe( "Private key of the token owner account in hex format (with or without 0x prefix). SECURITY: This is used only for transaction signing and is not stored." ) .default(process.env.PRIVATE_KEY as string), tokenAddress: z .string() .describe( "The contract address of the ERC1155 token collection (e.g., '0x76BE3b62873462d2142405439777e971754E8E77')" ), tokenId: z .string() .describe("The ID of the specific token to transfer (e.g., '1234')"), amount: z .string() .describe( "The quantity of tokens to send (e.g., '1' for a single NFT or '10' for 10 fungible tokens)" ), toAddress: z .string() .describe("The recipient wallet address that will receive the tokens"), network: defaultNetworkParam }, async ({ privateKey, tokenAddress, tokenId, amount, toAddress, network }) => { try { const result = await services.transferERC1155( tokenAddress as Address, toAddress as Address, BigInt(tokenId), amount, privateKey, network ) return mcpToolRes.success({ success: true, txHash: result.txHash, network, contract: tokenAddress, tokenId: result.tokenId, amount: result.amount, recipient: toAddress }) } catch (error) { return mcpToolRes.error(error, "transferring ERC1155 tokens") } } )
  • Supporting service function that performs the actual ERC1155 token transfer using safeTransferFrom on the blockchain.
    export async function transferERC1155( tokenAddressOrEns: string, toAddressOrEns: string, tokenId: bigint, amount: string, privateKey: string | `0x${string}`, network: string = "ethereum" ): Promise<{ txHash: Hash tokenId: string amount: string }> { // Resolve ENS names to addresses if needed const tokenAddress = (await resolveAddress( tokenAddressOrEns, network )) as Address const toAddress = (await resolveAddress(toAddressOrEns, network)) as Address // Ensure the private key has 0x prefix const formattedKey = typeof privateKey === "string" && !privateKey.startsWith("0x") ? (`0x${privateKey}` as `0x${string}`) : (privateKey as `0x${string}`) // Create wallet client for sending the transaction const walletClient = getWalletClient(formattedKey, network) // Send the transaction const hash = await walletClient.writeContract({ address: tokenAddress, abi: ERC1155_ABI, functionName: "safeTransferFrom", args: [ walletClient.account!.address, toAddress, tokenId, BigInt(amount), "0x" as `0x${string}` ], account: walletClient.account!, chain: walletClient.chain }) return { txHash: hash, tokenId: tokenId.toString(), amount } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bnb-chain/bnbchain-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server