Skip to content

Commit 8fca95a

Browse files
authored
Add an exemple to retrieve chain info (polkadot-js#125)
* add chain info * sidebar
1 parent a0d5a57 commit 8fca95a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Get chain information
3+
---
4+
5+
This example shows how to connect to the api and retrieve the chain information such as the token name, the ss58 format for address encoding and the token decimals.
6+
7+
```javascript
8+
// Import the API
9+
const { ApiPromise } = require('@polkadot/api');
10+
11+
async function main () {
12+
// Create a new instance of the api
13+
const api = await ApiPromise.create();
14+
// get the chain information
15+
const chainInfo = await api.registry.getChainProperties()
16+
17+
console.log(chainInfo);
18+
// for Polkadot this would print
19+
// {ss58Format: 0, tokenDecimals: [10], tokenSymbol: [DOT]}
20+
}
21+
22+
main().catch(console.error).finally(() => process.exit());;
23+
```

sidebars.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ module.exports = {
4444
'api/examples/promise/system-events',
4545
'api/examples/promise/transfer-events',
4646
'api/examples/promise/upgrade-chain',
47-
'api/examples/promise/typegen'
47+
'api/examples/promise/typegen',
48+
'api/examples/promise/chain-info',
4849
]
4950
},
5051
'api/FAQ'

0 commit comments

Comments
 (0)