const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
const plasmDefinitions = require('@plasm/types/interfaces/definitions');
const types = Object.values(plasmDefinitions).reduce((res, { types }) => ({ ...res, ...types }), {
// Other public RPC endpoints listed above
const wsProvider = new WsProvider('wss://rpc.dusty.plasmnet.io');
const api = await ApiPromise.create({
// aliases that don't do well as part of interfaces
'voting::VoteType': 'VoteType',
'voting::TallyType': 'TallyType',
// chain-specific overrides
Address: 'GenericAddress',
StakingLedger: 'StakingLedgerTo223',
ReferendumInfo: 'ReferendumInfoTo239',
// override duplicate type name
typesAlias: { voting: { Tally: 'VotingTally' } },
const [chain, nodeName, nodeVersion] = await Promise.all([
console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);
api.rpc.chain.subscribeNewHeads(async (header) => {
console.log(`Chain is at #${header.number}`);
main().catch(console.error);