How do I get the list of all the assets that are present and their supply in Statemint?
Ideally either with Polkadot-JS api or py-substrate-interface.
Substrate and Polkadot Stack Exchange is a question and answer site for developers building blockchains with the Substrate SDK. It only takes a minute to sign up.
Sign up to join this communityUsing PolkadotJS you can get the list of assets with this script:
const wsProvider = new WsProvider('wss://statemint.api.onfinality.io/public-ws');
const api = await ApiPromise.create({ provider: wsProvider });
const chain = await api.rpc.system.chain();
console.log(`----- Chain: ${chain} -----`);
const assets = await api.query.assets.metadata.entries();
assets.forEach(([{args: [id] } ,asset]) => {
console.log(`${id}: ${asset}`);
});
You can also query the list of assets using PolkadotJS UI calling the extrinsic metadata and disabling Include Option
Using py-substrate-interface it would be something like:
substrate = SubstrateInterface(url="wss://statemint-rpc.polkadot.io")
assets_metadata = substrate.query_map(
'Assets', 'Metadata'
)
for asset, metadata in assets_metadata:
print(f'Metadata of asset "{asset.value}": {metadata.value})')
You can find Python usage examples for other call- and storage functions here: https://polkascan.github.io/py-substrate-metadata-docs/statemint/#metadata
More info about query_map()
: https://github.com/polkascan/py-substrate-interface#query-a-mapped-storage-function