prepareERC1155Transfer
Prepare ERC1155 token transfer transactions for signing by generating transaction data with required parameters like contract addresses, token IDs, and amounts.
Instructions
Prepare an ERC1155 token transfer transaction for signing. Returns transaction data that can be signed and broadcast.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contractAddress | Yes | The address of the ERC1155 contract | |
| tokenAddress | No | DEPRECATED: Use contractAddress instead. The address of the ERC1155 contract | |
| fromAddress | Yes | The address sending the tokens | |
| toAddress | Yes | The address receiving the tokens | |
| tokenId | Yes | The ID of the token to query | |
| amount | Yes | The amount of tokens to transfer | |
| data | No | Additional data (default: '0x') | |
| provider | No | Optional. Either a network name or custom RPC URL. Use getAllNetworks to see available networks and their details, or getNetwork to get info about a specific network. You can use any network name returned by these tools as a provider value. | |
| chainId | No | Optional. The chain ID to use. | |
| gasLimit | No | ||
| gasPrice | No | ||
| maxFeePerGas | No | ||
| maxPriorityFeePerGas | No |
Implementation Reference
- src/tools/erc1155.ts:198-282 (registration)Registration of the 'prepareERC1155Transfer' MCP tool, including schema, description, and inline handler function.server.tool( "prepareERC1155Transfer", "Prepare an ERC1155 token transfer transaction for signing. Returns transaction data that can be signed and broadcast.", { contractAddress: contractAddressSchema, tokenAddress: tokenAddressSchema.optional(), // Deprecated fromAddress: addressSchema.describe("The address sending the tokens"), toAddress: addressSchema.describe("The address receiving the tokens"), tokenId: tokenIdSchema, amount: z.string().describe("The amount of tokens to transfer"), data: z.string().optional().describe("Additional data (default: '0x')"), provider: providerSchema, chainId: chainIdSchema, gasLimit: z.string().optional(), gasPrice: z.string().optional(), maxFeePerGas: z.string().optional(), maxPriorityFeePerGas: z.string().optional() }, async (params) => { // Map deprecated parameters const mapped = mapParameters(params); try { const contractAddr = mapped.contractAddress || params.tokenAddress; if (!contractAddr) { throw new Error('Either contractAddress or tokenAddress must be provided'); } // Prepare gas options const options = { gasLimit: params.gasLimit, gasPrice: params.gasPrice, maxFeePerGas: params.maxFeePerGas, maxPriorityFeePerGas: params.maxPriorityFeePerGas }; const txRequest = await ethersService.prepareERC1155Transfer( contractAddr, mapped.fromAddress, mapped.toAddress, mapped.tokenId, mapped.amount, params.data || '0x', mapped.provider, mapped.chainId, options ); return { content: [{ type: "text", text: `ERC1155 Transfer Transaction Prepared: Contract: ${contractAddr} Token ID: ${mapped.tokenId} From: ${mapped.fromAddress} To: ${mapped.toAddress} Amount: ${mapped.amount} Transaction Data: ${JSON.stringify({ to: txRequest.to, data: txRequest.data, value: txRequest.value || "0", gasLimit: txRequest.gasLimit?.toString(), gasPrice: txRequest.gasPrice?.toString(), maxFeePerGas: txRequest.maxFeePerGas?.toString(), maxPriorityFeePerGas: txRequest.maxPriorityFeePerGas?.toString(), chainId: txRequest.chainId }, null, 2)} This transaction is ready to be signed and broadcast.` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error preparing ERC1155 transfer transaction: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
- src/tools/erc1155.ts:216-281 (handler)The handler function that executes the tool logic: maps input parameters, prepares gas options, calls ethersService.prepareERC1155Transfer to get unsigned tx data, and returns formatted transaction details.async (params) => { // Map deprecated parameters const mapped = mapParameters(params); try { const contractAddr = mapped.contractAddress || params.tokenAddress; if (!contractAddr) { throw new Error('Either contractAddress or tokenAddress must be provided'); } // Prepare gas options const options = { gasLimit: params.gasLimit, gasPrice: params.gasPrice, maxFeePerGas: params.maxFeePerGas, maxPriorityFeePerGas: params.maxPriorityFeePerGas }; const txRequest = await ethersService.prepareERC1155Transfer( contractAddr, mapped.fromAddress, mapped.toAddress, mapped.tokenId, mapped.amount, params.data || '0x', mapped.provider, mapped.chainId, options ); return { content: [{ type: "text", text: `ERC1155 Transfer Transaction Prepared: Contract: ${contractAddr} Token ID: ${mapped.tokenId} From: ${mapped.fromAddress} To: ${mapped.toAddress} Amount: ${mapped.amount} Transaction Data: ${JSON.stringify({ to: txRequest.to, data: txRequest.data, value: txRequest.value || "0", gasLimit: txRequest.gasLimit?.toString(), gasPrice: txRequest.gasPrice?.toString(), maxFeePerGas: txRequest.maxFeePerGas?.toString(), maxPriorityFeePerGas: txRequest.maxPriorityFeePerGas?.toString(), chainId: txRequest.chainId }, null, 2)} This transaction is ready to be signed and broadcast.` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error preparing ERC1155 transfer transaction: ${error instanceof Error ? error.message : String(error)}` }] }; } }
- src/tools/erc1155.ts:202-215 (schema)Zod schema for input parameters of the prepareERC1155Transfer tool, including contract details, addresses, token info, gas options, and deprecated tokenAddress field.contractAddress: contractAddressSchema, tokenAddress: tokenAddressSchema.optional(), // Deprecated fromAddress: addressSchema.describe("The address sending the tokens"), toAddress: addressSchema.describe("The address receiving the tokens"), tokenId: tokenIdSchema, amount: z.string().describe("The amount of tokens to transfer"), data: z.string().optional().describe("Additional data (default: '0x')"), provider: providerSchema, chainId: chainIdSchema, gasLimit: z.string().optional(), gasPrice: z.string().optional(), maxFeePerGas: z.string().optional(), maxPriorityFeePerGas: z.string().optional() },