Skip to main content

Setting Operator for All Tokens

Authorizing an operator for all tokens is a crucial functionality within the ERC721 standard, allowing token owners to delegate management of their tokens. The edeXa ERC721 SDK's setOperatorForAll method facilitates this process, enabling seamless operator delegation. This guide provides detailed instructions and a code example for setting an operator for all tokens.


Overview of the setOperatorForAll Method

The setOperatorForAll method allows token owners to authorize an operator to manage all their tokens. This can include transferring tokens and other administrative tasks, depending on the permissions granted.


Prerequisites

  • Installation of the edeXa ERC721 SDK in your project.
  • An authentication token obtained through the SDK's authentication method. This token is necessary to authorize your requests.

Sample Code Snippet

Here is a JavaScript code snippet demonstrating the use of the setOperatorForAll method:

import { ERC721, Network } from 'edeXa-sdk';
async function setOperatorForAll() {
const settings = {
network: Network.SANDBOX, // Or Network.MAINNET for production
};
const erc721 = new ERC721({
...settings,
authorization: `Bearer ${token}`, // Replace `${token}` with your actual token
});

const dataToSetOperatorForAll = {
operator: 'Enter the username to set as operator for all tokens', // Required
approve: true, // Required boolean value to authorize the operator
chaincode: 'Optional smart contract name', // Managing tokens' smart contract
channel: 'Optional blockchain channel name', // Blockchain channel
};

try {
const setOperatorForAllResponse = await erc721.setOperatorForAll(
dataToSetOperatorForAll
);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterRequiredTypeDescription
operatorYesStringThe username of the user to be set as operator for all tokens.
approveYesBoolBoolean value true to authorize the operator for all tokens.
chaincodeNoStringName of the smart contract managing the tokens (optional).
channelNoStringName of the blockchain channel (optional).

Response Format

Upon successful operation, the setOperatorForAll method returns a response indicating the details of the operator setting action.

AttributeTypeDescription
operatorStringThe username or identifier of the set operator.
ownerStringThe username or identifier of the token owner.
approveBoolApproval status indicating successful setting of the operator.