1.4.9 • Published 11 months ago

polkadot-typed-api v1.4.9

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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:

PalletFully TypedTests 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";
1.4.6

11 months ago

1.4.9

11 months ago

1.4.8

11 months ago

1.4.7

11 months ago

1.4.5

1 year ago

1.4.4

1 year ago

1.4.3

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago