1.9.5 • Published 6 months ago

polkadot-api v1.9.5

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

polkadot-api

Features

  • Light client first: built on top of the new JSON-RPC spec to fully leverage the potential of light-clients (i.e: smoldot).
  • Delightful TypeScript support with types and docs generated from on-chain metadata.
  • First class support for storage reads, constants, transactions, events and runtime-calls.
  • Performant and lightweight: ships with multiple subpaths, so dApps don't bundle unnecessary assets.
  • Uses native BigInt, instead of large BigNumber libraries
  • Leverages dynamic imports to favour faster loading times.
  • Promise-based and Observable-based APIs: use the one that best suit your needs and/or coding style.
  • Use signers from your browser extension, or from a private key.
  • Easy integration with PJS-based extensions.

... and a lot lot more.

Overview

smoldot.ts

import { startFromWorker } from "polkadot-api/smoldot/from-worker"
import SmWorker from "polkadot-api/smoldot/worker?worker"

// Starting smoldot on a Worker (strongly recommended)
export const smoldot = startFromWorker(new SmWorker())

// Alternatively, we could have smoldot running on the main-thread, e.g:
// import { start } from "polkadot-api/smoldot"
// export const smoldot = start()

main.ts

import { createClient } from "polkadot-api"
import { getSmProvider } from "polkadot-api/sm-provider"
import { polkadotTypes } from "@polkadot-api/descriptors"
import { smoldot } from "./smoldot"

// dynamically importing the chainSpec improves the performance of your dApp
const smoldotRelayChain = import("polkadot-api/chains/polkadot").then(
  ({ chainSpec }) => smoldot.addChain({ chainSpec }),
)

// getting a `JsonRpcProvider` from a `smoldot` chain.
const jsonRpcProvider = getSmProvider(smoldotRelayChain)

// we could also create a `JsonRpcProvider` from a WS connection, eg:
// const jsonRpcProvider = WsProvider("wss://some-rpc-endpoint.io")

const polkadotClient = createClient(jsonRpcProvider)

// logging blocks as they get finalized
polkadotClient.finalizedBlock$.subscribe((block) => {
  console.log(`#${block.number} - ${block.hash} - parentHash: ${block.parent}`)
})

// pulling the latest finalized block
const block = await polkadotClient.getFinalizedBlock()

// obtaining a delightfully typed interface from the descriptors
// previously generated from the metadata
const polkadotApi = polkadotClient.getTypedApi(polkadotTypes)

// presenting the transferrable amount of a given account
const {
  data: { free, frozen },
} = await polkadotApi.query.System.Account.getValue(
  "15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5",
)
console.log(`Transferrable amount: ${free - frozen}`)

Documentation

1.8.2

8 months ago

1.8.1

9 months ago

1.8.0

9 months ago

1.7.9

9 months ago

1.7.8

9 months ago

1.9.5

6 months ago

1.7.7

10 months ago

1.9.4

6 months ago

1.7.6

10 months ago

1.9.3

6 months ago

1.7.5

10 months ago

1.9.2

6 months ago

1.7.4

10 months ago

1.9.1

7 months ago

1.7.3

10 months ago

1.9.0

7 months ago

1.7.2

10 months ago

1.7.1

10 months ago

1.7.0

10 months ago

1.6.7

10 months ago

1.8.4

7 months ago

1.6.6

10 months ago

1.8.3

7 months ago

1.6.4

11 months ago

1.6.5

10 months ago

1.6.3

11 months ago

1.2.0

1 year ago

1.0.2

1 year ago

1.6.2

11 months ago

1.6.1

11 months ago

1.6.0

11 months ago

1.4.1

11 months ago

1.4.0

11 months ago

1.2.1

12 months ago

1.1.0

1 year ago

1.5.1

11 months ago

1.3.3

12 months ago

1.5.0

11 months ago

1.3.2

12 months ago

1.3.1

12 months ago

1.3.0

12 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.11.0

1 year ago

0.12.0

1 year ago

0.11.1

1 year ago

0.13.0

1 year ago

0.12.1

1 year ago

0.11.2

1 year ago

0.13.1

1 year ago

0.13.2

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.8.0

1 year ago

0.9.1

1 year ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.5

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.2

1 year ago

0.1.3

1 year ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago