Skip to main content

Spender Allowance Limit

Checking the approved spending limit for a specific spender is an essential operation in the edeXa ERC20 API. This functionality allows you to determine how many tokens a particular spender is authorized to spend on behalf of an account owner. You can use the checkAllowanceLimit method to inquire about the approved allowance limit.


Prerequisites

  • The client making this request must be authenticated using the edeXa SDK. This involves obtaining a valid token through the authentication method.

  • Ensure that an operator has been set for the spender. The operator is the user who has been granted permission to spend tokens on behalf of another user. This should be done using the setOperator method.


Sample Code Snippet

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

// SDK.js
import { ERC20, Network } from 'edeXa-sdk';

async function checkAllowanceLimit() {
const erc20 = new ERC20({
...settings,
authorization: `Bearer ${token}`,
});

const settings = {
network: Network.SANDBOX, // or Network.MAINNET for the mainnet network
};

const dataToCheckAllowance = {
spender:
'Enter the username of the user for whom you want to check the approved allowance limit.',
chaincode:
'The name of the smart contract or chaincode managing the tokens (optional)',
channel: 'The name of the channel in the blockchain network (optional)',
};

try {
const checkAllowanceResponse = await erc20.checkAllowanceLimit(
dataToCheckAllowance
);
// Handle success
} catch (error) {
// Handle error
}
}

Important Notes

  • Authentication Token: Replace the token in the authorization header with your actual authentication token.
  • Asynchronous Execution: The checkAllowanceLimit function is an async function, using await for the erc20.checkAllowanceLimit method's promise to resolve. The response will be logged on successful resolution. Errors are caught and logged with console.error.

Before using the checkAllowanceLimit method, ensure that you have set an operator for the spender and approved some allowance to that particular spender. This ensures that you can accurately check their approved allowance limit.


Request Parameters

The dataToCheckAllowance object includes the following parameters for the checkAllowanceLimit method:

ParameterRequiredTypeDescriptionDefault
spenderYesStringEnter the username of the user for whom you want to check the approved allowance limit.
chaincodeOptionalStringThe name of the smart contract or chaincode managing the tokens. (Optional, use default if not provided)Default chaincode
channelOptionalStringThe name of the channel in the blockchain network. (Optional, use default if not provided)Default chaincode
  • The spender represents the user for whom you are checking the approved allowance limit. This user is typically the operator who has been granted spending permission by the account owner.
  • Optional parameters chaincode and channel can be provided to specify the smart contract or chaincode managing the tokens and the blockchain network channel. If not provided, the default values will be used.

Response Format

The response from the checkAllowanceLimit method includes the following attributes:

KeyTypeDescription
allowanceLimitNumberThe approved allowance limit of tokens for spending by the operator.
toStringThe username of the user who is the spender.