Skip to main content
Glama

prepareERC1155SetApprovalForAll

Prepare transaction data to approve or revoke an operator's access to all your ERC1155 tokens from a specific contract for signing and broadcasting.

Instructions

Prepare an ERC1155 setApprovalForAll transaction for signing. Returns transaction data that can be signed and broadcast.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractAddressYesThe address of the ERC1155 contract
tokenAddressNoDEPRECATED: Use contractAddress instead. The address of the ERC1155 contract
operatorYesThe address to approve/revoke for all tokens
approvedYesWhether to approve (true) or revoke (false)
fromAddressYesThe address that owns the tokens
providerNoOptional. 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.
chainIdNoOptional. The chain ID to use.
gasLimitNo
gasPriceNo
maxFeePerGasNo
maxPriorityFeePerGasNo

Implementation Reference

  • The main handler function for the 'prepareERC1155SetApprovalForAll' tool. It processes parameters (mapping deprecated fields), prepares gas options, delegates to ethersService for transaction preparation, formats the unsigned transaction details, and handles errors.
    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.prepareERC1155SetApprovalForAll( contractAddr, mapped.operator, params.approved, mapped.fromAddress, mapped.provider, mapped.chainId, options ); return { content: [{ type: "text", text: `ERC1155 Set Approval For All Transaction Prepared: Contract: ${contractAddr} Owner: ${mapped.fromAddress} Operator: ${mapped.operator} Approved: ${params.approved ? 'Yes' : 'No'} 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 setApprovalForAll transaction: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
  • Input schema using Zod validation for the tool parameters, including contract address, operator, approval status, owner, provider options, and gas parameters.
    contractAddress: contractAddressSchema, tokenAddress: tokenAddressSchema.optional(), // Deprecated operator: addressSchema.describe("The address to approve/revoke for all tokens"), approved: z.boolean().describe("Whether to approve (true) or revoke (false)"), fromAddress: addressSchema.describe("The address that owns the tokens"), provider: providerSchema, chainId: chainIdSchema, gasLimit: z.string().optional(), gasPrice: z.string().optional(), maxFeePerGas: z.string().optional(), maxPriorityFeePerGas: z.string().optional() },
  • The server.tool call that registers the 'prepareERC1155SetApprovalForAll' tool with the MCP server, including description, input schema, and handler function.
    server.tool( "prepareERC1155SetApprovalForAll", "Prepare an ERC1155 setApprovalForAll transaction for signing. Returns transaction data that can be signed and broadcast.", { contractAddress: contractAddressSchema, tokenAddress: tokenAddressSchema.optional(), // Deprecated operator: addressSchema.describe("The address to approve/revoke for all tokens"), approved: z.boolean().describe("Whether to approve (true) or revoke (false)"), fromAddress: addressSchema.describe("The address that owns the tokens"), 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.prepareERC1155SetApprovalForAll( contractAddr, mapped.operator, params.approved, mapped.fromAddress, mapped.provider, mapped.chainId, options ); return { content: [{ type: "text", text: `ERC1155 Set Approval For All Transaction Prepared: Contract: ${contractAddr} Owner: ${mapped.fromAddress} Operator: ${mapped.operator} Approved: ${params.approved ? 'Yes' : 'No'} 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 setApprovalForAll transaction: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
  • Supporting helper function in ERC1155 service that executes the signed setApprovalForAll transaction. The tool's prepare version likely uses a similar approach but with populateTransaction to prepare unsigned tx data.
    export async function setApprovalForAll( ethersService: EthersService, contractAddress: string, operatorAddress: string, approved: boolean, provider?: string, chainId?: number, options: TokenOperationOptions = {} ): Promise<ethers.TransactionResponse> { metrics.incrementCounter('erc1155.setApprovalForAll'); return timeAsync('erc1155.setApprovalForAll', async () => { try { // Get signer from ethers service const signer = ethersService['getSigner'](provider, chainId); // Create contract instance with signer const contractWithSigner = new ethers.Contract(contractAddress, ERC1155_ABI, signer); // Prepare transaction overrides const overrides: ethers.Overrides = {}; if (options.gasLimit) overrides.gasLimit = options.gasLimit; if (options.gasPrice) overrides.gasPrice = options.gasPrice; if (options.maxFeePerGas) overrides.maxFeePerGas = options.maxFeePerGas; if (options.maxPriorityFeePerGas) overrides.maxPriorityFeePerGas = options.maxPriorityFeePerGas; if (options.nonce !== undefined) overrides.nonce = options.nonce; // Set approval const tx = await contractWithSigner.setApprovalForAll(operatorAddress, approved, overrides); return tx; } catch (error) { logger.debug('Error setting ERC1155 approval', { contractAddress, operatorAddress, approved, error }); throw handleTokenError(error, 'Failed to set token approval'); } }); }

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