Skip to main content

setApprovalForAll

The setApprovalForAll method for the ERC-1155 token standard provides an ability for an Ethereum address (typically representing a smart contract or another user) to manage multiple token IDs on behalf of the current token holder. By setting this approval, the approved address can transfer tokens on the holder's behalf, facilitating operations like batch transfers or trading on decentralized platforms. The method is embedded within the ERC1155Instance object, accessible through the appropriate method of the EdexaClient or the related library.

Method Signature

async setApprovalForAll(
to: string,
approved: boolean,
signer: WalletSigner
): Promise<TransactionResponse>

Parameters

ParameterTypeDescription
tostringThe Ethereum address that is being granted or revoked access to manage the tokens.
approvedbooleanA boolean indicating whether approval is being granted (true) or revoked (false).
signerWalletSignerThe wallet signer instance responsible for signing the transaction.

Returns

  • A Promise resolving to a TransactionResponse, detailing the outcome of the approval transaction.

Usage Example

First, instantiate the desired ERC-1155 token contract:

const erc1155 = edexaClient.getERC1155Instance("your ERC-1155 contract address here");

Then, use the setApprovalForAll method to grant or revoke approval:

const operatorAddress = "0x2c360D20cE6b3D8b466511eF093C9177c3817B94";
const approvalStatus = true; // Set to false to revoke approval
const signer = edexaClient.createWalletSigner("your private key");

const approvalTransaction = await erc1155.setApprovalForAll(operatorAddress, approvalStatus, signer);
console.log(`Approval Transaction Hash: ${approvalTransaction.hash}`);

Notes

  • The setApprovalForAll method is pivotal for scenarios where an external entity (like a smart contract or a marketplace) needs to execute transactions involving multiple token IDs on behalf of the token holder.

  • It's of utmost importance to exercise caution when granting approvals. Ensure you trust the external entity with the management of your tokens, and always be ready to revoke access if necessary.