prepareERC721Approval
Generate transaction data to authorize another address to transfer a specific ERC721 NFT token on your behalf, ready for signing and broadcasting.
Instructions
Prepare an ERC721 NFT approval transaction for signing. Returns transaction data that can be signed and broadcast.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contractAddress | Yes | ||
| tokenId | Yes | ||
| approvedAddress | Yes | ||
| fromAddress | Yes | ||
| provider | No | ||
| chainId | No | ||
| gasLimit | No | ||
| gasPrice | No | ||
| maxFeePerGas | No | ||
| maxPriorityFeePerGas | No |
Implementation Reference
- src/tools/erc721.ts:552-613 (handler)The main handler function for the 'prepareERC721Approval' MCP tool. It fetches NFT collection info, prepares gas options, calls ethersService.prepareERC721Approval to get the unsigned transaction request, formats it as JSON, and returns it in the MCP response format.async (params) => { try { // Get NFT collection info for display const nftInfo = await ethersService.getERC721CollectionInfo( params.contractAddress, params.provider, params.chainId ); // Prepare gas options const options = { gasLimit: params.gasLimit, gasPrice: params.gasPrice, maxFeePerGas: params.maxFeePerGas, maxPriorityFeePerGas: params.maxPriorityFeePerGas }; const txRequest = await ethersService.prepareERC721Approval( params.contractAddress, params.approvedAddress, params.tokenId, params.fromAddress, params.provider, params.chainId, options ); return { content: [{ type: "text", text: `ERC721 Approval Transaction Prepared: Collection: ${nftInfo.name} (${nftInfo.symbol}) Token ID: ${params.tokenId} Owner: ${params.fromAddress} Approved Address: ${params.approvedAddress} 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 NFT approval transaction: ${error instanceof Error ? error.message : String(error)}` }] }; } }
- src/tools/erc721.ts:540-551 (schema)Zod schema defining the input parameters for the prepareERC721Approval tool, including contract details, addresses, chain info, and optional gas parameters.{ contractAddress: contractAddressSchema, tokenId: tokenIdSchema, approvedAddress: addressSchema, fromAddress: addressSchema, provider: providerSchema, chainId: chainIdSchema, gasLimit: z.string().optional(), gasPrice: z.string().optional(), maxFeePerGas: z.string().optional(), maxPriorityFeePerGas: z.string().optional() },
- src/tools/erc721.ts:538-614 (registration)Registration of the prepareERC721Approval tool with the MCP server using server.tool(), including name, description, schema, and handler."prepareERC721Approval", "Prepare an ERC721 NFT approval transaction for signing. Returns transaction data that can be signed and broadcast.", { contractAddress: contractAddressSchema, tokenId: tokenIdSchema, approvedAddress: addressSchema, fromAddress: addressSchema, provider: providerSchema, chainId: chainIdSchema, gasLimit: z.string().optional(), gasPrice: z.string().optional(), maxFeePerGas: z.string().optional(), maxPriorityFeePerGas: z.string().optional() }, async (params) => { try { // Get NFT collection info for display const nftInfo = await ethersService.getERC721CollectionInfo( params.contractAddress, params.provider, params.chainId ); // Prepare gas options const options = { gasLimit: params.gasLimit, gasPrice: params.gasPrice, maxFeePerGas: params.maxFeePerGas, maxPriorityFeePerGas: params.maxPriorityFeePerGas }; const txRequest = await ethersService.prepareERC721Approval( params.contractAddress, params.approvedAddress, params.tokenId, params.fromAddress, params.provider, params.chainId, options ); return { content: [{ type: "text", text: `ERC721 Approval Transaction Prepared: Collection: ${nftInfo.name} (${nftInfo.symbol}) Token ID: ${params.tokenId} Owner: ${params.fromAddress} Approved Address: ${params.approvedAddress} 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 NFT approval transaction: ${error instanceof Error ? error.message : String(error)}` }] }; } } );