Ink! Developer Workshop - Web3bridge Edition

Objectives

Slide 2: What is Polkadot API?

Frontend Typescript library for interacting with substrate chains and the smart contracts deployed onto them as well. Polkadot API, commonly called PAPI, is an npm library and can be installed using the following command:

**npm i polkadot-api**

PAPI provides a number of primitive that helps a Typescript/NodeJS D’app to connect with a Substrate (consequently, a Smart contract) chain. There are multiple ways to connect to a chain but we will focus on the JSON-RPC Provider (& Websocket Provider). Once we have this provider, we can easily connect to a chain using:

import { createClient } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws-provider/node";

const client = createClient(
	getWsProvider("wss://testnet-passet-hub.polkadot.io")
);

PAPI, by default, exposes a **polkadot-api/ink**module that can be used to interact with smart contracts on a low-level. This is exported automatically from the normal polkadot-api library and needs no further installation. It can be useful for querying and performing dry-run operations on a smart contract. There is also an ink! specific library that can be installed using:

npm i @polkadot-api/sdk-ink .

This library is a high-level implementation that abstracts a number of redundancy from the Frontend developer and also provides better handling and interactions. This slides demos the low-level approach and compares it with the *sdk-ink.*

Connecting to a Wallet

To perform transactions (write messages that update storage), it is necessary to have a signer available and this is exactly what browser wallets offer us. We have to start with connecting to our wallets. The available wallets to use are: