System API
The System API provides a way to query the system information of the blockchain. It allows you to query the chain name, version, health, and more.
This API is available through the SystemApi
class from the polkadart
package.
Sample usage
You will get the following output:
Methods
There are several methods available in the SystemApi
class that allow you to query the system information of the blockchain. Here are some of the most commonly used methods:
name
Get the node’s implementation name. Plain old string.
version
Get the node implementation’s version. Should be a semver string.
chain
Get the chain’s name. Given as a string identifier.
chainType
Get the chain’s type.
health
Return health status of the node.
Node is considered healthy if it is:
- connected to some peers (unless running in dev mode)
- not performing a major sync
localPeerId
Returns the base58-encoded PeerId of the node.
localListenAddresses
Returns the multi-addresses that the local node is listening on
The addresses include a trailing /p2p/
with the local PeerId, and are thus suitable to
be passed to addReservedPeer
or as a bootnode address for example.
peers
Returns currently connected peers
unsafe: This method is only active with appropriate flags
accountNextIndex
Returns the next valid index (aka nonce) for given account.
This method takes into consideration all pending transactions currently in the pool and if no transactions are found in the pool it fallbacks to query the index from the runtime (aka. state nonce).
dryRun
Dry run an extrinsic at a given block. Return SCALE encoded ApplyExtrinsicResult.
nodeRoles
Returns the roles the node is running as.
properties
Get a custom set of properties as a JSON object, defined in the chain spec.
addReservedPeer
Adds a reserved peer. Returns the empty string or an error. The string
parameter should encode a p2p
multiaddr.
/ip4/198.51.100.19/tcp/30333/p2p/QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV
is an example of a valid, passing multiaddr with PeerId attached.
unsafe: This method is only active with appropriate flags
removeReservedPeer
Remove a reserved peer. Returns the empty string or an error. The string
should encode only the PeerId e.g. QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV
.
unsafe: This method is only active with appropriate flags
reservedPeers
Returns the list of reserved peers
addLogFilter
Adds the supplied directives to the current log filter unsafe: This method is only active with appropriate flags
resetLogFilter
Resets the log filter to Substrate defaults unsafe: This method is only active with appropriate flags
syncState
Returns the state of the syncing of the node: starting block, current best block, highest known block.