Now that our project is ready, we can initialize the setup for Polkadot API. I, very much, propose once again to have a look on Polkadot API's documentation (https://papi.how), but in case, you either prefer this format, or you have been there and are back, then let's go for it. :)
Of course we need, first of all, to add the polkadot-api
dependency in our project.
Let's do that by running:
$ bun install polkadot-api
That’s it! The installation is all set.
Ready for the next step? We’ll be configuring PAPI.
But before we dive in, it’s important to get a basic understanding of how PAPI works.
Throughout this tutorial, we'll explore the following Polkadot API (PAPI) use cases for connecting to the network:
You might be wondering why I’m bringing this up at this point. Here’s why:
To properly configure each project with the Polkadot API, it's important to know which chains we’ll be interacting with upfront. This allows us to set everything up correctly from the start.
While it’s certainly possible to add new chains later if needed, for the sake of this tutorial, we’ll configure everything in advance. This approach keeps things organized and helps ensure a smoother workflow.
Given the steps we’ll be taking, we’ll need to configure three different chains:
polkadot
relay chainpeople
system parachain andcollectives
parachainPolkadot API comes with a handy bundle of chainspecs for both well-known-chains
and system-chains
to make your life easier.
This means you don’t have to worry about finding endpoints for fetching metadata or chainspecs (which are needed for the light client). All of this is bundled right into PAPI.
As we move forward, you’ll see just how helpful this can be in simplifying the setup process.
In the next step, we will find out more details about PAPI's code generation and "adding chains" functionality.