Polkadot Backend API Creation

achinta das
Coinmonks
4 min readFeb 16, 2022

--

Polkadot is a next-generation blockchain protocol connecting multiple specialized blockchains into one unified network. Designed as part of a broad vision for a web that returns control to individuals over internet monopolies, Polkadot builds on the revolutionary promise of previous blockchain networks while offering several fundamental advantages.

First things first, if you have never touched Polkadot, I recommend reading their whitepaper here or checking out their medium. Let’s get you up and code if you have a base understanding of Polkadot.

About the project: In this article, I am creating an API that connects the Polkadot test net, generates accounts, Gets balance, and sends transactions on the Polkadot test net called Westend. In this project, we are using Polkadot.js. Polkadot-JS is a collection of tools that interfaces with the Polkadot blockchain in a granular way.

Summary: In this project, we will archive the down below function to create the polka dot backend.

Tech Stack: Tech Stack was used in this project.

Polkadot Accounts

Cryptography

  • Hashing Algorithm: The hashing algorithm used in Polkadot is Blake2b.
  • Keypairs and signing: Polkadot uses Schnorrkel/Ristretto x25519 (“sr25519”) as its key derivation and signing algorithm.
  • Address Type: The address format used in Substrate-based chains is SS58. SS58 is a modification of Base-58-check from Bitcoin with some minor changes.

Prerequisites

NodeJS

To run this API, NodeJS should be installed in the running environment. Please follow these steps:

  • Download the installer from NodeJS WebSite https://nodejs.org
  • Run the installer.
  • Follow the installer steps, agree on the license agreement, and click the following button.

Now, test NodeJS by printing its version using the following command in Command Prompt:

Step 1: The project runs as follows step:

  • Once the project is cloned and installed, this command should be run in the project location in the terminal.
    npm run node

Step 2: Connect Postman

Step 3: Create two accounts and fund one account.

Step 4. Decrypting & Encrypting:

  • Decrypting the addresses using sr25519.
  • Encrypting the public key using sr25519.

Step 5: Balance Check :

Step 6: Transfer Coin

Send a post request for the transaction. http://localhost:8081/getBalance/createPolkaTrx

Sidenote: most BN operations have a “n” version, like div and divn, mul and muln. Theis expects a number, while the standard a BN instance.

  • Check transaction details on Westend Explorer. Paste transaction id in it

Explorer: https://westend.subscan.io/

Github link: https://github.com/Achinta123/polkadot_backend.git

Contact: achintad171@gmail.com

--

--