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 theauthorization
header with your actual authentication token. - Asynchronous Execution: The
totalSupply
function is anasync
function, usingawait
for theerc20.totalSupply
method's promise to resolve. The total supply will be logged on successful resolution. Errors are caught and logged withconsole.error
.
Request Parameters
The dataToGetTotalSupply
object contains the following optional parameters for the totalSupply
method:
Parameter | Type | Description | Default |
---|---|---|---|
chaincode | String | The name of the smart contract or chaincode managing the tokens. | Default chaincode |
channel | String | The name of the channel in the blockchain network. | Default channel |
- If
chaincode
andchannel
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:
Key | Type | Description |
---|---|---|
supply | number | The total supply of minted tokens |