Skip to content
Polkadot-API

Getting Started

Community templates

If you want to quickly get a project up and running, check out the following community templates:

Installation

Start by installing polkadot-api, and download the latest metadata from the chain you want to connect to and generate the types:

Now you can create a PolkadotClient instance with a provider of your choice and start interacting with the API:

1. Create the provider and Start the client

// `dot` is the name we gave to `npx papi add`
import {  } from "@polkadot-api/descriptors"
import {  } from "polkadot-api"
import {  } from "polkadot-api/sm-provider"
import {  } from "polkadot-api/chains/polkadot"
import {  } from "polkadot-api/smoldot"
 
// if interested, check out how to create a smoldot instance in a WebWorker
// http://papi.how/providers/sm#webworker
const  = ()
 
// Connect to the polkadot relay chain.
const  = (
  (() => .({  })),
)

2. Start consuming the client!

// With the `client`, you can get information such as subscribing to the last
// block to get the latest hash:
..(() =>
  .(., .),
)
 
// To interact with the chain, you need to get the `TypedApi`, which includes
// all the types for every call in that chain:
const  = .()
 
// get the value for an account
const  = await ....(
  "16JGzEsi8gcySKjpmxHVrkLTHdFHodRepEz8n244gNZpr9J",
)

3. Discover our documentation!

To continue learning about PAPI, we recommend reading about:

  1. CLI & Codegen. Fully grasp how to generate descriptors, and why does it matter for PAPI.
  2. Providers. Discover all options that our providers offer! You'll need a provider to proceed with the client.
  3. Client. Get information for blocks, metadata, etc. Essentially, everything generic that does not depend on the runtime itself. For runtime specifics, keep reading...
  4. Typed API. The cherry on top of the cake! Interact with the network: transactions, storage entries, runtime apis, and others!
  5. Signers. You'll find here how PAPI abstracts away signers, and how can be used to sign transactions!