📁 Chaindata JS Wrapper
This repository is a JS helper library for the @talismn/chaindata repository, enabling easy fetching of assets and config files for developers when building within the polkadot ecosystem.
The goals of this repo are:
- Allow developers to easily use the @talismn/chaindata repository in applications
- Allow developers to discover availability of chains & chains assets
Note: This repoository is in development and may contain bugs and change without warning. Use at your own discretion.
Usage
Installation
yarn add @talismn/chaindata-js
Importing
import chaindata from 'chaindata'
Discover chains
Discover which chains are available
const chains = await chaindata.chains()
The returned object contains key:value pairs of all available chain ids and names.
{
"0": "Polkadot",
"2": "Kusama",
// ... etc
}
Load a chain by ID
Fetch a chains by ID and load all relevant information. In this instance Polkadot (id: 0).
const chain = await chaindata.chain(0)
The returned object contains all relevant information about the requested chain.
{
"id": "0",
"name": "Polkadot",
"description": "Polkadot is a heterogeneous multichain with shared security and interoperability",
"isRelay": true,
"links":{
"Website": "https://polkadot.network",
"Twitter": "https://twitter.com/Polkadot",
"Support": "https://support.polkadot.network/support/home",
"Discord": "https://discord.com/invite/wGUDt2p",
"Github": "https://github.com/paritytech/polkadot"
},
"assets":{
"logo": "logo.svg",
"banner": "banner.png",
"card": "card.png"
},
"rpcs": [
"wss://rpc.polkadot.io"
],
"status": "READY",
}
Fetch chain details
To access any fields on the chains, using the instance above
const name = chain.name
Which returns the value requested, i.e:
Polkadot
Fetch chain assets
To access any assets on the chain, using the instance above:
const logo = chain.asset.logo
Which returns a string as the full path to the asset file.
https://raw.githubusercontent.com/TalismanSociety/chaindata/master/0/assets/logo.svg
And can be used in an img tag:
<img src={logo}/>
Notes
- The main chain config and chain details are fetched on the fly, as requested, and cached locally for the session