Exchanges and market data aggregators need accurate supply figures to display market capitalization and token metrics.
NEM exposes the supply of XEM, the native currency, through the REST API.
This tutorial shows how to query the total supply and derive the circulating supply from it.
The snippet uses the NODE_URL environment variable to set a NEM mainnet node.
Why mainnet?
Other tutorials typically run against testnet to avoid spending real funds.
This one is different because it queries fixed mainnet account addresses to calculate the circulating supply, so
NODE_URL must point to a mainnet node.
The total supply of XEM is fixed.
All 8'999'999'999 XEM were created in the nemesis block and no new XEM is ever minted.
This tutorial reads values like the supply and divisibility from the API rather than hard-coding them, so the same
approach also works for other mosaics, including those whose supply can change.
The code sends a GET request to the /mosaic/supplyGET endpoint, passing the XEM mosaic identifier nem:xem as
the mosaicId query parameter.
The response is a JSON object with the mosaic identifier and its current supply, expressed in
whole units.
# Read the mosaic's divisibility to convert balances to whole unitsdefinition_path=f'/mosaic/definition?mosaicId={MOSAIC_ID}'withurllib.request.urlopen(f'{NODE_URL}{definition_path}')asresponse:definition=json.loads(response.read().decode())properties={prop['name']:prop['value']forpropindefinition['properties']}divisibility=int(properties['divisibility'])
// Read the mosaic's divisibility to convert balances to whole unitsconstdefinitionPath=`/mosaic/definition?mosaicId=${MOSAIC_ID}`;constdefinitionResponse=awaitfetch(`${NODE_URL}${definitionPath}`);constdefinition=awaitdefinitionResponse.json();constproperties=Object.fromEntries(definition.properties.map(property=>[property.name,property.value]));constdivisibility=parseInt(properties.divisibility,10);
The supply fetched in the previous step is already in whole units, but the account balances read in the next steps are
reported in atomic units.
To convert values to the same units, this step first fetches the mosaic's divisibility.
This value is then used to convert the balances from atomic units to whole units.
The /mosaic/definitionGET endpoint returns the mosaic's definition, which includes the divisibility.
For nem:xem, the divisibility is 6.
A portion of the total supply is held by accounts that are not part of the open market:
Treasury: A reserve account that holds team-controlled XEM.
Nemesis: The account that signed the nemesis block.
It cannot send transactions after the nemesis block, so any XEM held by this account is effectively out of
circulation.
Namespace rental sink: Collects the fees paid to register namespaces.
Mosaic rental sink: Collects the fees paid to create mosaics.
The code queries each account with the /account/getGET endpoint and sums their balances.
Each balance is divided by 10divisibility, using the divisibility value fetched in the previous step, to convert it
from atomic units to whole units.
For nem:xem, this divisor is 1'000'000.