Quickly get started with experimenting with the Polkadot API. Includes hot-reloading and a clean Typescript environment to work with.
Getting started should be simple - simply npm install, and you're off to the races.
Be sure npm and npx is up to date and working:
npm install npm@latest -gnpm installYou can start a hot reloading server with tsc-watch, which will automatically apply your code changes live:
npm run startAlternatively, you can also build the project and run the files manually inside dist/:
npm run buildIf you want to add a custom chain, such as a local one, you need to first get the metadata for your chain. You can replace ws://localhost:9944 with your node's appropriate URL:
npx papi add custom --wsUrl ws://localhost:9944Then, make sure you are using the WebSocket client (wsClient or withWebSocket(url)) and your custom metadata:
// ...
const wsClient = await withWebSocket("ws://localhost:9944");
const dotApi = wsClient.getTypedApi(custom);
// Then, you can make calls like this...
const last_runtime_upgrade = await dotApi.query.System.LastRuntimeUpgrade.getValue();
console.log(last_runtime_upgrade)
// ...