Getting Started
Community templates
If you want to quickly get a project up and running, check out the following community templates:
- PAPI Starter Template: React, shadcn/ui, PolkaHub, React Query
- Create Polkadot dApp: React, tailwind, ReactiveDot, DOTConnect
- Create Dot App: Many different template stacks, including React or Vue.
- POP CLI: Ink! smart contracts with frontend integration.
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 = (
(() => .({ })),
)// `dot` is the name we gave to `npx papi add`
import { } from "@polkadot-api/descriptors"
import { } from "polkadot-api"
import { } from "polkadot-api/ws"
// Connect to the polkadot relay chain.
const = (("wss://dot-rpc.stakeworld.io"))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:
- CLI & Codegen. Fully grasp how to generate descriptors, and why does it matter for PAPI.
- Providers. Discover all options that our providers offer! You'll need a provider to proceed with the client.
- Client. Get information for blocks, metadata, etc. Essentially, everything generic that does not depend on the runtime itself. For runtime specifics, keep reading...
- Typed API. The cherry on top of the cake! Interact with the network: transactions, storage entries, runtime apis, and others!
- Signers. You'll find here how PAPI abstracts away signers, and how can be used to sign transactions!