Is there a way to query whether a chain has a native token and what it is?
For instance can I query Moonbeam, to find that it's native token is GLMR(Glimmer). Similarly for the rest of the parachains.
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 communityYou have this information in the chain-spec of the network, if you want to query it, you can use RPC queries for it.
Specifically the system_properties RPC call
You can query it using CURL:
curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "system_properties", "params": []}' https://moonbeam.public.blastapi.io
And you will get the token symbol of the network, GLMR in this case.
{"SS58Prefix":1284,"tokenDecimals":18,"tokenSymbol":"GLMR"},"id":1
Or you can use JS code, with PolkadotJS library.
const wsProvider = new WsProvider('wss://moonbeam.public.blastapi.io');
const api = await ApiPromise.create({ provider: wsProvider });
const properties = await api.rpc.system.properties();
console.log(properties.toHuman());
And you got the token symbol:
{
ss58Format: null,
tokenDecimals: [ '18' ],
tokenSymbol: [ 'GLMR' ],
SS58Prefix: 1284
}
You can also use Sidecar's endpoint runtime/spec
.
So you would need to :
wss://moonbeam.api.onfinality.io/public-ws
(unless you are running a parachain node yourself)env profile
as shown in the READMEhttp://127.0.0.1:8080/runtime/spec
{
"at": {
"height": "2316673",
"hash": "0xafdd015b8b04c039d5e6753cf9363e57a9a65ac5127a62b525b57761fc14533e"
},
"authoringVersion": "3",
"transactionVersion": "2",
"implVersion": "0",
"specName": "moonbeam",
"specVersion": "1803",
"chainType": {
"live": null
},
"properties": {
"ss58Format": null,
"tokenDecimals": [
"18"
],
"tokenSymbol": [
"GLMR"
],
"SS58Prefix": "1284"
}
}