The universal typed wrapper for polkadot ApiPromise.
import { ApiPromise, WsProvider } from "@polkadot/api";
import { api } from "polkadot-typed-api";
const connecton = await ApiPromise.create({
provider: new WsProvider(/*provider url*/),
});
const validators = await api.query.staking.validators(connecton);
import { ApiPromise, WsProvider } from "@polkadot/api";
const connecton = await ApiPromise.create({
provider: new WsProvider(/*provider url*/),
});
const validators = await connecton.query.staking.validators();
await api.query.staking.validators(connecton); // returns typed data
type Staking_Validators_Json = {
commission: number;
blocked: boolean;
};
await connecton.query.staking.validators(); // Returns Codec and you should guess what to do with that!
npm i polkadot-typed-api
import { api } from "polkadot-typed-api";
import { ApiPromise, WsProvider } from "@polkadot/api";
import { api } from "polkadot-typed-api";
const connecton = await ApiPromise.create({
provider: new WsProvider(/*provider url*/),
});
const data = api["query" || "rpc" || "tx"][palletName][methodName](connection, ...params);
Pallet | Fully Typed | Tests Coverage |
---|---|---|
api.query.nominationPools | - | 5% |
api.query.proxy | - | 5% |
api.query.system | + | 100% ✅ |
api.query.timestamp | + | 100% ✅ |
api.query.session | - | 10% |
api.query.staking | - | 5% |
api.rpc.system | - | 1% |
api.tx.balances | + | 0% |
api.tx.nominationPools | + | 0% |
api.call.authorityDiscoveryApi | + | 100% ✅ |
api.call.accountNonceApi | + | 100% ✅ |
import type { Staking_Ledger_Json } from "polkadot-typed-api/types/api/query/staking/ledger";
import { api } from "polkadot-typed-api";
// Define variable type
let unblocking: Staking_Ledger_Json['unlocking'] = [];
const data = await api.query.staking.ledger(connection, account); // Staking_Ledger_Json
if (data) {
// Set-Up variable value
unblocking = data.unblocking;
}
-
awaitTransaction
- await transaction cancellation -
polkadotExplorerUrl
- get subscan or another explorer link url by params
import { utils } from "polkadot-typed-api";