2

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.

2 Answers 2

5

You 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
}
1

You can also use Sidecar's endpoint runtime/spec. So you would need to :

  • Install Sidecar locally
  • Add an .env file that points to one of Moonbeam's public endpoints, e.g. wss://moonbeam.api.onfinality.io/public-ws (unless you are running a parachain node yourself)
  • Run Sidecar with your new env profile as shown in the README
  • Then you can access the endpoint from your browser http://127.0.0.1:8080/runtime/spec
  • The result is again in JSON format
    {
  "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"
  }
}
1
  • 1
    Another interesting alternative is to use Sidecar, thanks @dominique
    – Alex Bean
    Commented Nov 17, 2022 at 14:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.