Skip to main content

Checking Approval Status

This guide describes how to check the approval status for a specific spender using the ERC1155 API, an essential feature for managing token allowances and spender permissions within your blockchain application.

Overview of the getAppriveStatus Method

The getApproveStatus method allows you to query whether a spender is authorized to use tokens on behalf of the token owner, including the amount they are allowed to use. This functionality is crucial for ensuring secure token transactions and managing user permissions.


Prerequisites

  • Installed the edeXa-sdk in your project.
  • An authentication token obtained through the SDK's authentication method. This token is necessary to authorize your requests.
  • Optionally, set an allowance for the spender using the approveTokenAccess method.

Sample Code Snippet

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

import { ERC1155, Network } from 'edeXa-sdk';

async function checkApprovalStatus() {
// Configuration settings for the ERC1155 instance
const settings = {
network: Network.SANDBOX, // Use Network.MAINNET for production environments
};

const erc1155 = new ERC1155({
...settings,
authorization: `Bearer ${token}`, // Replace `${token}` with your actual token
});

// Data required to check the approval status
const dataToCheckApproval = {
spender: 'usernameOfSpender', // Username of the spender
chaincode: 'optionalChaincodeName', // Optional chaincode name
channel: 'optionalChannelName', // Optional blockchain channel
};

try {
// Query the approval status
const checkApprovalResponse = await erc1155.getApproveStatus(
dataToCheckApproval
);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterTypeRequiredDescription
spenderStringYesThe username of the user for whom to check the approval status.
chaincodeStringNoThe name of the smart contract or chaincode managing the tokens.
channelStringNoThe name of the blockchain channel where the operation occurs.

Response Format

Upon successfully querying the approval status, the getApproveStatus method returns a response object containing:

KeyTypeDescription
statusBooleanIndicates whether the spender is authorized.
toStringThe username of the spender.