JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 25
  • Score
    100M100P100Q56083F
  • License MIT

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

Dynamic JSON Badge

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-api

Usage

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%
api.rpc.system - 1%
api.tx.balances + 0%
api.tx.nominationPools + 0%
api.call.authorityDiscoveryApi + 100% ✅
api.call.accountNonceApi + 100% ✅

Types usage

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;
}

Useful Utils

  • awaitTransaction - await transaction cancellation
  • polkadotExplorerUrl - get subscan or another explorer link url by params
import { utils } from "polkadot-typed-api";