In this step, we'll kick off our journey by setting up a basic TypeScript project where we'll explore different integration examples of the Polkadot API (or PAPI, as I'll call it from here on out—because who doesn’t love saving a few keystrokes?).
While you could use other toolkits for JavaScript and TypeScript apps (like Vite or simply node), I've opted for Bun. Why? Because it's the quickest way to get a TypeScript-ready project up and running without getting bogged down in the nitty-gritty details.
Keep in mind, this tutorial is focused on showing you how to set up PAPI and work with various providers. We're not diving deep into how to set up a TypeScript project from scratch—there are plenty of resources out there for that.
Now that we’ve got that covered, let’s jump into the first step!
Note: Installing Bun Before we dive in, you'll need to have Bun installed on your system. For the installation process, please follow the official Bun documentation.
From this point on, I'll assume that Bun is already installed and ready to go!
Create an empty directory and cd
into it:
$ mkdir polkadot-api-tutorial && cd polkadot-api-tutorial
Scaffold an empty Bun project with the interactive bun init
command (Press enter
to accept the default answer for each prompt):
$ bun initbun init helps you get started with a minimal project and tries toguess sensible defaults. Press ^C anytime to quit.package name (polkadot-api-tutorial):entry point (index.ts):Done! A package.json file was saved in the current directory.+ index.ts+ .gitignore+ tsconfig.json (for editor auto-complete)+ README.mdTo get started, run:bun run index.ts
Once completed the following files should appear in your structure:
bun
(one of the reasons I chose this over other options).console.log("Hello via Bun!");
In order to make sure that everything works as expected and the project is correctly setup, feel free and run the following command:
$ bun run index.ts
You should see the following output:
Hello via Bun!
That's it.. our project's initial setup is ready and now we can move forward to setup Polkadot API in the project.