Skip to main content
Glama

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
NameRequiredDescriptionDefault
contractAddressYes
tokenIdYes
approvedAddressYes
fromAddressYes
providerNo
chainIdNo
gasLimitNo
gasPriceNo
maxFeePerGasNo
maxPriorityFeePerGasNo

Implementation Reference

  • 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)}` }] }; } }
  • 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() },
  • 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)}` }] }; } } );

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/crazyrabbitLTC/mcp-ethers-server'

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