Skip to main content

Total Supply of Minted Tokens

To inquire about the total supply of minted tokens with the ERC20 API, you can use the totalSupply method. This allows you to retrieve the total supply of tokens issued.


Prerequisites

  • Authenticate the client using the edeXa SDK. For authentication details, see the authentication method.

  • Ensure that tokens have been minted using the specific minting function, as described in Mint Tokens.


Sample Code Snippet

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

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

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

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

const dataToGetTotalSupply = {
chaincode(optional): 'The name of the smart contract or chaincode managing the tokens',
channel(optional): 'The name of the channel in the blockchain network'
}

try {
const totalSupplyResponse = await erc20.totalSupply(dataToGetTotalSupply);
// 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 totalSupply function is an async function, using await for the erc20.totalSupply method's promise to resolve. The total supply will be logged on successful resolution. Errors are caught and logged with console.error.

Request Parameters

The dataToGetTotalSupply object contains the following optional parameters for the totalSupply method:

ParameterTypeDescriptionDefault
chaincodeStringThe name of the smart contract or chaincode managing the tokens.Default chaincode
channelStringThe name of the channel in the blockchain network.Default channel
  • If chaincode and channel are not provided, the default chaincode and channel will be used.

Response Format

The response for a successful total supply inquiry includes the following attribute:

KeyTypeDescription
supplynumberThe total supply of minted tokens