dotcodeschool

dotcodeschool

Submit Feedback

Initialize a Basic TypeScript Project

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!

bun init

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 init
bun init helps you get started with a minimal project and tries to
guess 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.md
To get started, run:
bun run index.ts

Once completed the following files should appear in your structure:

  1. package.json: This file is the heart of your project’s configuration. It defines the metadata for your project, including the project name, version, dependencies, scripts, and more. It's similar to the package.json file used in npm projects.
  2. bun.lockb: This is Bun’s lock file, similar to package-lock.json in npm or yarn.lock in Yarn.
  3. tsconfig.json: This file is automatically generated as TypeScript is installed by default with bun (one of the reasons I chose this over other options).
  4. .gitignore: This file specifies which files and directories should be ignored by Git when committing to a repository. Purpose: It typically includes common files like node_modules/, log files, and lock files that should not be tracked in version control.
  5. README.md: The basic markdown file that is often generated as part of the project setup and (actually) is the one you are reading right now
  6. index.ts: The initial TypeScript index file (where our "entry" is), and it should read at this point the following 1 line of code: 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.

Loading...

Initialize a Basic TypeScript Project

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!

bun init

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 init
bun init helps you get started with a minimal project and tries to
guess 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.md
To get started, run:
bun run index.ts

Once completed the following files should appear in your structure:

  1. package.json: This file is the heart of your project’s configuration. It defines the metadata for your project, including the project name, version, dependencies, scripts, and more. It's similar to the package.json file used in npm projects.
  2. bun.lockb: This is Bun’s lock file, similar to package-lock.json in npm or yarn.lock in Yarn.
  3. tsconfig.json: This file is automatically generated as TypeScript is installed by default with bun (one of the reasons I chose this over other options).
  4. .gitignore: This file specifies which files and directories should be ignored by Git when committing to a repository. Purpose: It typically includes common files like node_modules/, log files, and lock files that should not be tracked in version control.
  5. README.md: The basic markdown file that is often generated as part of the project setup and (actually) is the one you are reading right now
  6. index.ts: The initial TypeScript index file (where our "entry" is), and it should read at this point the following 1 line of code: 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.

Loading...

Next