Package Exports
- polkadot-typed-api
- polkadot-typed-api/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (polkadot-typed-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Polkadot Typed Api
The universal typed wrapper for polkadot ApiPromise.
General idea
Use this
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);Instead of this
import { ApiPromise, WsProvider } from "@polkadot/api";
const connecton = await ApiPromise.create({
provider: new WsProvider(/*provider url*/),
});
const validators = await connecton.query.staking.validators();Because
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!Installation
npm i polkadot-typed-apiUsage
Import
import { api } from "polkadot-typed-api";Typescript
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);Typed Pallets:
| 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% |
| rpc.system.accountNextIndex | - | 1% |