diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 4f077ba5..9ced6aea 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -25,6 +25,8 @@ jobs: # If untrusted content changed, opens a draft PR for review. check-untrusted: runs-on: ubuntu-latest + env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - uses: actions/checkout@v4 @@ -34,7 +36,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22 cache: pnpm - run: pnpm install diff --git a/content/courses/papi-intro-tutorial/papi-intro-tutorial.mdx b/content/courses/papi-intro-tutorial/papi-intro-tutorial.mdx deleted file mode 100644 index 362cea53..00000000 --- a/content/courses/papi-intro-tutorial/papi-intro-tutorial.mdx +++ /dev/null @@ -1,63 +0,0 @@ ---- -order: 3 -slug: papi-intro-tutorial -title: "Polkadot API: An Introduction to multi-chain" -author: Nikos Kontakis -author_url: https://github.com/wirednkod -description: Do the first steps with this tutorial, on the Polkadot API, a powerful tool for interacting with the Polkadot network. -level: Beginner -language: Typescript -tags: ["typscript", "tutorial", "course", "frontend"] -prerequisites: [] -what_youll_learn: ["Introduction to the new Polkadot API"] -estimated_time: 1 # Estimated time to complete in hours -last_updated: "2024-11-10" ---- - -# Introduction to the new Polkadot API - -Welcome to the first interactive tutorial of the new Polkadot API. - -This is a guided tutorial intended to teach readers how to set up, use and interact with Substrate based chains by using the new [Polkadot-API](https://github.com/polkadot-api/polkadot-api). - -### What is the fuss about - -The new Polkadot API (PAPI) is: - -- 🪶 **light client first**: built on top of the [new JSON-RPC spec](https://paritytech.github.io/json-rpc-interface-spec/) to fully leverage the potential of light-clients; -- 💡 delightful **TypeScript support** with types and docs generated from on-chain metadata; -- 📋 first class support for **storage** reads, **constants**, **transactions**, **events** and **runtime calls**; -- 🔗 perform **multiple connections** to different chains simultaneously; -- 🔄 prepare for upcoming **runtime updates** by generating multiple descriptors and performing **compatibility checks**; -- 🚀 **performant and lightweight**: ships with multiple subpaths, so dApps don't bundle unnecessary assets; -- 🔢 uses **native BigInt**, instead of large BigNumber libraries; -- ⚡ leverages dynamic imports to favour **faster loading times**; -- ✨ **promise-based and Observable-based APIs**: use the one that best suits your needs and/or coding style; -- 🔑 use **signers** from your browser extension, or from a private key; -- 🧩 easy integration with **PJS-based extensions**. - -While Polkadot API is a very interesting approach and way of interacting with Substrate based chains, I have found it quite challenging to twist my mindset from existing approaches (e.g. PolkadotJS) to installing and using Polkadot-API. - -Having said that, after a few retries and with some help from the creators ([Josep](https://github.com/josepot) and [Victor](https://github.com/voliva)) I found myself loving, using it and adding it in existing and new projects. - -### What this tutorial is about - -This tutorial is meant for developers who want to install Polkadot-API (or aka PAPI) in a project, add correctly some chains in the project and interact with them with various ways (web socket, smoldot etc.). - -In order to address this, we will set up a simple TypeScript project with the minimum needed configuration, run the basic steps needed to "integrate"/"add" (use whatever word fits you best here), the chains we need to connect to in our project and then create some sample calls. - -### What this tutorial is **not** about - -- **Not a Comprehensive Guide:** This tutorial focuses on the bare minimum needed to use the Polkadot API in a TypeScript project. It will help you set up a basic project, integrate various chains (including well-known, system chains, or those from a given chainspec), and utilize the Polkadot API. - -- **Not a Substitute for Foundational Knowledge:** While this tutorial is designed to be accessible even if you have little prior experience with the Polkadot API or interactions with Substrate chains, it does not replace a basic introduction to these topics. We recommend familiarizing yourself with the fundamentals, either before or alongside this tutorial. - -- **Not an All-in-One Resource:** This is a step-by-step guide aimed at helping you set up the Polkadot API in your project. It is highly recommended to refer to the official [Polkadot API documentation (http://papi.how)](http://papi.how) throughout your learning process and ensure you have a basic understanding of [TypeScript](https://www.typescriptlang.org/). - -- **Not for Experts Only:** You don’t need to be an expert in every topic covered here, but having some exposure to them will enhance your understanding. - -This tutorial is divided into sections, each targeting specific learning goals and offering natural pause points. All content is open source and freely accessible [here](https://github.com/wirednkod/papi-intro-tutorial). - -Suggestions for improvement, comments, issues, and pull requests are welcome. - -Enjoy, and I hope you find this tutorial informative and valuable! diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/introduction-to-the-new-polkadot-api.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/introduction-to-the-new-polkadot-api.mdx deleted file mode 100644 index a30c64a6..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/introduction-to-the-new-polkadot-api.mdx +++ /dev/null @@ -1,52 +0,0 @@ ---- -slug: introduction-to-the-new-polkadot-api -title: Introduction to the new Polkadot API -order: 1 -description: Introduction to the new Polkadot API ---- - -Welcome to the first interactive tutorial of the new Polkadot API. - -This is a guided tutorial intended to teach readers how to set up, use and interact with Substrate based chains by using the new [Polkadot-API](https://github.com/polkadot-api/polkadot-api). - -### What is the fuss about - -The new Polkadot API (PAPI) is: - -- 🪶 **light client first**: built on top of the [new JSON-RPC spec](https://paritytech.github.io/json-rpc-interface-spec/) to fully leverage the potential of light-clients; -- 💡 delightful **TypeScript support** with types and docs generated from on-chain metadata; -- 📋 first class support for **storage** reads, **constants**, **transactions**, **events** and **runtime calls**; -- 🔗 perform **multiple connections** to different chains simultaneously; -- 🔄 prepare for upcoming **runtime updates** by generating multiple descriptors and performing **compatibility checks**; -- 🚀 **performant and lightweight**: ships with multiple subpaths, so dApps don't bundle unnecessary assets; -- 🔢 uses **native BigInt**, instead of large BigNumber libraries; -- ⚡ leverages dynamic imports to favour **faster loading times**; -- ✨ **promise-based and Observable-based APIs**: use the one that best suits your needs and/or coding style; -- 🔑 use **signers** from your browser extension, or from a private key; -- 🧩 easy integration with **PJS-based extensions**. - -While Polkadot API is a very interesting approach and way of interacting with Substrate based chains, I have found it quite challenging to twist my mindset from existing approaches (e.g. PolkadotJS) to installing and using Polkadot-API. - -Having said that, after a few retries and with some help from the creators ([Josep](https://github.com/josepot) and [Victor](https://github.com/voliva)) I found myself loving, using it and adding it in existing and new projects. - -### What this tutorial is about - -This tutorial is meant for developers who want to install Polkadot-API (or aka PAPI) in a project, add correctly some chains in the project and interact with them with various ways (web socket, smoldot etc.). - -In order to address this, we will set up a simple TypeScript project with the minimum needed configuration, run the basic steps needed to "integrate"/"add" (use whatever word fits you best here), the chains we need to connect to in our project and then create some sample calls. - -### What this tutorial is **not** about - -- **Not a Comprehensive Guide:** This tutorial focuses on the bare minimum needed to use the Polkadot API in a TypeScript project. It will help you set up a basic project, integrate various chains (including well-known, system chains, or those from a given chainspec), and utilize the Polkadot API. - -- **Not a Substitute for Foundational Knowledge:** While this tutorial is designed to be accessible even if you have little prior experience with the Polkadot API or interactions with Substrate chains, it does not replace a basic introduction to these topics. We recommend familiarizing yourself with the fundamentals, either before or alongside this tutorial. - -- **Not an All-in-One Resource:** This is a step-by-step guide aimed at helping you set up the Polkadot API in your project. It is highly recommended to refer to the official [Polkadot API documentation (http://papi.how)](http://papi.how) throughout your learning process and ensure you have a basic understanding of [TypeScript](https://www.typescriptlang.org/). - -- **Not for Experts Only:** You don’t need to be an expert in every topic covered here, but having some exposure to them will enhance your understanding. - -This tutorial is divided into sections, each targeting specific learning goals and offering natural pause points. All content is open source and freely accessible [here](https://github.com/wirednkod/papi-intro-tutorial). - -Suggestions for improvement, comments, issues, and pull requests are welcome. - -Enjoy, and I hope you find this tutorial informative and valuable! diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/codegen-adding-chains.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/codegen-adding-chains.mdx deleted file mode 100644 index 38d85400..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/codegen-adding-chains.mdx +++ /dev/null @@ -1,151 +0,0 @@ ---- -slug: codegen-adding-chains -title: Codegen & "adding" chains -order: 3 -last_updated: "2025-05-08" # Current date ---- - -# Codegen & "adding" chains - -### Some background first - -To connect to a blockchain network like Polkadot, the fundamental requirement is a provider, which acts as a bridge between your application and the chain. Providers typically connect to an RPC (Remote Procedure Call) endpoint, which allows your app to retrieve data like blocks and events. However, simply connecting to the chain doesn’t enable full interaction. - -To interact with the chain — whether by querying storage, making transactions, or calling runtime methods — you also need to understand what data is available and how to format it. This is where metadata becomes crucial. The chain's metadata contains a detailed description of all the storage items, runtime functions, and transactions available on that network, as well as their data types. - -Here’s how the process works: - -During runtime, PAPI can automatically request the metadata from the chain you're connected to. From this metadata, it generates codecs (serialization and deserialization tools) to communicate with the chain's functions and storage. Before development, however, you need to have this information ready, in order to make your life easier on knowing how to communicate with the chain. - -PAPI simplifies this with its CLI (Command Line Interface), which allows you to download the chain’s metadata ahead of time. This metadata is then used to generate all the necessary type descriptors, so you don’t have to manually figure out the structure of every interaction. - -In practice, using the CLI to download metadata ensures that your app stays in sync with the specific network you're developing for, especially if that chain undergoes runtime upgrades or type changes​. - -That CLI's syntax is: - -```shell -$ npx papi add --help - -Usage: polkadot-api add [options] - -Add a new chain spec to the list - -Arguments: - key Key identifier for the chain spec - -Options: - --config Source for the config file - -f, --file Source from metadata encoded file - -w, --wsUrl Source from websocket URL - -c, --chainSpec Source from chain spec file - -n, --name Source from a well-known chain (choices: "ksmcc3", "paseo", - "polkadot", "polkadot_collectives", "rococo_v2_2", "westend2", [...]") - --wasm Source from runtime wasm file - --no-persist Do not persist the metadata as a file - --skip-codegen Skip running codegen after adding - -h, --help display help for command -``` - -The `papi add` command is used to register a new chain in your Polkadot project. When running this command, you need to provide a key — a unique identifier that will be used as a constant name when generating code for the chain. Additionally, you specify a source for the chain’s metadata using one of the following flags: - -- `-f`, `-w`, `-c`, `-n`, or `--wasm`, depending on whether the metadata comes from a file, websocket, chain, or other source. - -The command then downloads the latest metadata for the chain and stores it in a .papi folder. This folder contains: - -1. A **configuration file** called `polkadot-api.json`, which holds the setup information for the chain. -2. **A metadata file** named `${key}.scale`, which contains the chain's specific metadata for later use. - -This structure ensures that all the necessary metadata for interacting with the chain is preloaded and organized, streamlining your development process. - -## Adding Polkadot chain - -Now that the CLI is understood, let's get going with this and run: - -```shell -$ bunx papi add dot -n polkadot -``` - -> Note: bunx is the equivelent package runner for bun (as npx is for npm). -> You can read [more here](https://bun.sh/docs/cli/bunx). - -What happened here? -Using `bunx` we asked (politely) from Polkadot API to fetch for you, in a `dot` "variable", the metadata from (the well-known-chain) `polkadot`. - -The outcome of the command should be the following: - -```shell -$ bunx papi add dot -n polkadot - -✔ Metadata saved as .papi/metadata/dot.scale -Saved new spec "dot" -Reading metadata -CLI Building entry: .papi/descriptors/src/index.ts -CLI Using tsconfig: tsconfig.json -CLI tsup v8.3.0 -CLI Target: esnext -CJS Build start -ESM Build start -ESM .papi/descriptors/dist/index.mjs 9.88 KB -ESM .papi/descriptors/dist/metadataTypes-FYTIEX4M.mjs 146.06 KB -ESM .papi/descriptors/dist/descriptors-BGFWDDEF.mjs 25.73 KB -ESM ⚡️ Build success in 20ms -CJS .papi/descriptors/dist/index.js 190.36 KB -CJS ⚡️ Build success in 20ms -Compilation started -Compilation successful -bun install -bun install v1.1.7 (b0b7db5c) - - + @polkadot-api/descriptors@.papi/descriptors - - 1 package installed [19.00ms] -``` - -So what PAPI did for you, behind the scenes? - -1. Created a directory called `.papi` and under it in the dir `metadata` saved all the latest metadata for `polkadot`; -2. In your `package.json` file added a dependency link to the descriptors that are created: `"@polkadot-api/descriptors": "file:.papi/descriptors",`. -3. Under the `.papi` directory, created a PAPI configuration file called `polkadot-api.json` that looks like this: - -``` -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - } - } -} -``` - -and contains in `entries` the "variable" `dot`, linked to the respective chain and metadata; - -> Note: the command `bunx papi add dot -n polkadot` is "same" if we used an RPC endpoint with the flag -w. "Same" should not be lightly taken into account. This is not entiredly correct. If the PAPI's entries are used instead of an RPC endpoint, then the metadata are downloaded in a more decentralized manner - instead of being downladed from 1 specific url. - -> `$ bunx papi add -w wss://polkadot-collectives-rpc.polkadot.io dot` -> -> but since `polkadot` is a known chain, the first command will suffice - -In just few words - configured all the paths and needed dependencies with just 1 command. - -## Adding people and collectives parachains - -Let's run the commands for the rest of the chains we need: - -```shell -$ bunx papi add people -n polkadot_people -``` - -and - -```shell -$ bunx papi add collectives -n polkadot_collectives -``` - -## Configuration Complete - -Configuration is now finished! All the necessary chains are set up in your project, and the metadata is neatly organized in a structured directory. - -> Note: It’s a great idea to add PAPI to the "postinstall" script in your package.json to automate the generation of types after installation. (see `package.json` file for how that looks.) diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/index.ts deleted file mode 100644 index 2a5e4b80..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/index.ts +++ /dev/null @@ -1 +0,0 @@ -console.log("Hello via Bun!"); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/codegen-adding-chains/files/source/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/collectives-system-chain.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/collectives-system-chain.mdx deleted file mode 100644 index ce1467e2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/collectives-system-chain.mdx +++ /dev/null @@ -1,32 +0,0 @@ ---- -slug: collectives-system-chain -title: COLLECTIVES System Chain -order: 9 -last_updated: "2025-05-08" # Current date ---- - -# COLLECTIVES System Chain - -The Polkadot Collectives parachain was added in [Referendum 81](https://polkadot.polkassembly.io/referendum/81) and exists only on Polkadot (i.e., there is no Kusama equivalent). The Collectives chain hosts on-chain collectives that serve the Polkadot network, such as the Fellowship and Polkadot Alliance. - -The queries of a collective are (using as example the fellowship) the following `FellowshipCollective, FellowshipCore, FellowshipReferenda, FellowshipSalary, FellowshipTreasury` and we will specifically use the `FellowshipCollective` for gathering the fellowship members and their `rank`. - -Note: For more information about the fellowship collective, and specifics on the members and ranks, since this is not the main subject of the tutorial, feel free to read here: https://polkadot-fellows.xyz/ - -To receive all the entries of a query without specifing an address (or an input), PAPI provides a `getEntries()` method which returns an array of results, of the expected structure. -So in our case this will be something like: - -```ts -const rawMembers = - await collectivesApi.query.FellowshipCollective.Members.getEntries(); -``` - -Once this is executed then we can parse the results and return only the needed address, and rank for each Fellowship member. - -```ts -const data = rawMembers.map((m) => ({ address: m.keyArgs[0], rank: m.value })); -``` - -You can try to console the result in a table, using the `console.table` [static method](https://developer.mozilla.org/en-US/docs/Web/API/console/table_static). - -Similar scripts are used in the Fellowship Dashboard - `https://polkadot-fellows.xyz` and the results can be seen at the first page's table, where all members of the fellowship appear. diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/bun.lockb deleted file mode 100644 index 414ec864..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/index.ts deleted file mode 100644 index 0634e7c6..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/index.ts +++ /dev/null @@ -1,94 +0,0 @@ -import process from "node:process"; - -import { collectives,dot, people } from "@polkadot-api/descriptors"; -import { - createClient, - type PolkadotClient, - type SS58String, -} from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -async function printChainInfo(client: PolkadotClient) { - // **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. - const chainSpec = await client.getChainSpecData(); - const finalizedBlock = await client.getFinalizedBlock(); - console.log( - `Connected to ${chainSpec.name} at block ${finalizedBlock.number}.\n`, - ); -} - -async function getBalance( - polkadotClient: PolkadotClient, - address: SS58String, -): Promise { - const dotApi = polkadotClient.getTypedApi(dot); - const accountInfo = await dotApi.query.System.Account.getValue(address); - const { free, reserved } = accountInfo.data; - return free + reserved; -} - -async function getDisplayName( - peopleClient: PolkadotClient, - address: SS58String, -): Promise { - const peopleApi = peopleClient.getTypedApi(people); - const accountInfo = - await peopleApi.query.Identity.IdentityOf.getValue(address); - const displayName = accountInfo?.[0].info.display.value?.asText(); - return displayName; -} - -interface FellowshipMember { - address: SS58String; - rank: number; -} - -async function getFellowshipMembers( - collectivesClient: PolkadotClient, -): Promise { - const collectivesApi = collectivesClient.getTypedApi(collectives); - const rawMembers = - await collectivesApi.query.FellowshipCollective.Members.getEntries(); - const data = rawMembers.map((m) => { - return { address: m.keyArgs[0], rank: m.value }; - }); - return data; -} - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - await printChainInfo(polkadotClient); - - const peopleClient = makeClient("wss://polkadot-people-rpc.polkadot.io"); - await printChainInfo(peopleClient); - - const collectivesClient = makeClient( - "wss://polkadot-collectives-rpc.polkadot.io", - ); - await printChainInfo(collectivesClient); - - const members = await getFellowshipMembers(collectivesClient); - - console.log("Generating table..."); - const table = []; - for (const { address, rank } of members) { - const balance = await getBalance(polkadotClient, address); - const displayName = await getDisplayName(peopleClient, address); - table.push({ rank, displayName, address, balance }); - } - - table.sort((a, b) => b.rank - a.rank); - console.table(table); - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/solution/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/bun.lockb deleted file mode 100644 index 12334da2..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/index.ts deleted file mode 100644 index 28b6e9b3..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/index.ts +++ /dev/null @@ -1,109 +0,0 @@ -import process from "node:process"; - -// TODO: Import `collectives` from `"@polkadot-api/descriptors"`. -import { dot, people } from "@polkadot-api/descriptors"; -import { - createClient, - type PolkadotClient, - type SS58String, -} from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -async function printChainInfo(client: PolkadotClient) { - // **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. - const chainSpec = await client.getChainSpecData(); - const finalizedBlock = await client.getFinalizedBlock(); - console.log( - `Connected to ${chainSpec.name} at block ${finalizedBlock.number}.\n`, - ); -} - -async function getBalance( - polkadotClient: PolkadotClient, - address: SS58String, -): Promise { - const dotApi = polkadotClient.getTypedApi(dot); - const accountInfo = await dotApi.query.System.Account.getValue(address); - const { free, reserved } = accountInfo.data; - return free + reserved; -} - -async function getDisplayName( - peopleClient: PolkadotClient, - address: SS58String, -): Promise { - const peopleApi = peopleClient.getTypedApi(people); - const accountInfo = - await peopleApi.query.Identity.IdentityOf.getValue(address); - const displayName = accountInfo?.[0].info.display.value?.asText(); - return displayName; -} - -// TODO: -// - Create a new type safe `interface` called `FellowshipMember`. -// - It has two fields: -// - `address` which is of type `SS58String`. -// - `rank` which is of type `number`. - -// TODO: -// - Create a new `async` function `getFellowshipMembers`: -// - It has a single parameter `collectivesClient` of type `PolkadotClient`. -// - It returns an array of fellowship members: `Promise`. -// - Write the logic of the `getFellowshipMembers` function: -// - Call the `getTypedApi` method on the `collectivesClient` variable. -// - The `getTypedApi` method should include the parameter `collectives`, which we imported above. -// - Assign the result to a new constant `collectivesApi`. -// - Call `collectivesApi.query.FellowshipCollective.Members.getEntries()`. -// - `await` the result, and assign it to a new constant `rawMembers`. -// - Extract the `address` and `rank` from `rawMembers`: -// - `map` the items of `rawMembers` to access the individual members `m`. -// - You can access the `address` of the member by calling `m.keyArgs[0]`. -// - You can access the `rank` of the member by calling `m.value`. -// - Assign the mapped data to a new constant `fellowshipMembers`. -// - Make sure the data is in the structure of `FellowshipMember`. -// - Return the `fellowshipMembers` constant. - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - await printChainInfo(polkadotClient); - - const peopleClient = makeClient("wss://polkadot-people-rpc.polkadot.io"); - await printChainInfo(peopleClient); - - // TODO: - // - Make a new client connection to `"wss://polkadot-collectives-rpc.polkadot.io"`. - // - Assign the result to a constant `collectivesClient`. - // - Call `printChainInfo(collectivesClient)` and await the result. - - // TODO: - // - Call `getFellowshipMembers` with the parameter `collectivesClient`. - // - `await` the result, and assign it to a new constant `members`. - - // TODO: - // - Create a new constant `table` which is an empty array that we will fill. - // - Create a `for` loop over `members`, extracting the `address` and `rank`. - // - Rather than use the hardcoded address below, use the `address` variable from `members`. - // - Bring the logic to get the `balance` and `displayName` into your loop. - // - Replace our `console.log`, and instead `push` all of the data into the `table` array. - // - `table.push({ rank, displayName, address, balance })` - const address = "15DCZocYEM2ThYCAj22QE4QENRvUNVrDtoLBVbCm5x4EQncr"; - const balance = await getBalance(polkadotClient, address); - const displayName = await getDisplayName(peopleClient, address); - console.log(`Balance of ${displayName} (${address}) is ${balance}.`); - - // TODO: - // - We can sort the table by `rank`: `table.sort((a, b) => b.rank - a.rank)`. - // - Finally, print the table using `console.table(table)`, rather than `console.log`. - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/collectives-system-chain/files/template/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/connection-process.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/connection-process.mdx deleted file mode 100644 index 463cb1d7..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/connection-process.mdx +++ /dev/null @@ -1,173 +0,0 @@ ---- -slug: connection-process -title: Connection Process -order: 4 -last_updated: "2025-05-08" # Current date ---- - -# Connection Process - -The connection process for PAPI follows a structured workflow that ensures your application can both connect to and interact with the Polkadot network. -Here’s a step-by-step explanation: - -### 1. Provider Setup - -The first step in connecting to a chain is creating a provider, which acts as a communication bridge between your application and the blockchain. PAPI offers multiple ways to establish this connection, such as using: - -- **getWsProvider (the WebSocket Provider)**: Connects via a WebSocket URL, often used for real-time interactions. -- **Smoldot Provider**: A lightweight option that runs a light client in the browser, particularly useful for environments with limited resources​. - -In your app, you would initialize the provider like this: - -```ts -import { getWsProvider } from "polkadot-api/ws-provider/web"; -... -const provider = new getWsProvider('wss://rpc.polkadot.io'); -``` - -### 2. Client Initialization - -After setting up the provider, the next step is to initialize a **client**. - -The client is responsible for making RPC calls to the chain, fetching metadata, and enabling interactions like querying storage or sending transactions. - -```ts -import { createClient, type PolkadotClient } from "polkadot-api"; -... -const client: PolkadotClient = createClient(provider); -``` - -The `PolkadotClient` interface shapes the top-level API for polkadot-api. Once we get a client using `createClient` function, the following can be used: - -```ts -interface PolkadotClient { - /** - * Retrieve the ChainSpecData as it comes from the [JSON-RPC - * spec](https://paritytech.github.io/json-rpc-interface-spec/api/chainSpec.html) - */ - getChainSpecData: () => Promise; - - /** - * Observable that emits `BlockInfo` from the latest known finalized block. - * It's a multicast and stateful observable, that will synchronously replay - * its latest known state. - */ - finalizedBlock$: Observable; - /** - * @returns Latest known finalized block. - */ - getFinalizedBlock: () => Promise; - - /** - * Observable that emits an Array of `BlockInfo`, being the first element the - * latest known best block, and the last element the latest known finalized - * block. It's a multicast and stateful observable, that will synchronously - * replay its latest known state. This array is an immutable data structure; - * i.e. a new array is emitted at every event but the reference to its - * children are stable if the children didn't change. - * - * Note that subscribing to this observable already supersedes the need of - * subscribing to `finalizedBlock$`, since the last element of the array will - * be the latest known finalized block. - */ - bestBlocks$: Observable; - /** - * @returns Array of `BlockInfo`, being the first element the latest - * known best block, and the last element the latest known - * finalized block. - */ - getBestBlocks: () => Promise; - - /** - * Observable to watch Block Body. - * - * @param hash It can be a block hash, `"finalized"`, or `"best"` - * @returns Observable to watch a block body. There'll be just one event - * with the payload and the observable will complete. - */ - watchBlockBody: (hash: string) => Observable; - /** - * Get Block Body (Promise-based) - * - * @param hash It can be a block hash, `"finalized"`, or `"best"` - * @returns Block body. - */ - getBlockBody: (hash: string) => Promise; - - /** - * Get Block Header (Promise-based) - * - * @param hash It can be a block hash, `"finalized"` (default), or - * `"best"` - * @returns Block hash. - */ - getBlockHeader: (hash?: string) => Promise; - - /** - * Broadcast a transaction (Promise-based) - * - * @param transaction SCALE-encoded tx to broadcast. - * @param at It can be a block hash, `"finalized"`, or `"best"`. - * That block will be used to verify the validity of - * the tx, retrieve the next nonce, - * and create the mortality taking that block into - * account. - */ - submit: ( - transaction: HexString, - at?: HexString, - ) => Promise; - /** - * Broadcast a transaction and returns an Observable. The observable will - * complete as soon as the transaction is in a finalized block. - * - * @param transaction SCALE-encoded tx to broadcast. - * @param at It can be a block hash, `"finalized"`, or `"best"`. - * That block will be used to verify the validity of - * the tx, retrieve the next nonce, - * and create the mortality taking that block into - * account. - */ - submitAndWatch: ( - transaction: HexString, - at?: HexString, - ) => Observable; - - /** - * Returns an instance of a `TypedApi` - * - * @param descriptors Pass descriptors from `@polkadot-api/descriptors` - * generated by `papi` CLI. - */ - getTypedApi: (descriptors: D) => TypedApi; - - /** - * This will `unfollow` the provider, disconnect and error every subscription. - * After calling it nothing can be done with the client. - */ - destroy: () => void; - - /** - * This API is meant as an "escape hatch" to allow access to debug endpoints - * such as `system_version`, and other useful endpoints that are not spec - * compliant. - * - * @example - * - * const systemVersion = await client._request("system_version", []) - * const myFancyThhing = await client._request< - * { value: string }, - * [id: number] - * >("very_fancy", [1714]) - * - */ - _request: = any[]>( - method: string, - params: Params, - ) => Promise; -} -``` - -> Note: `PolkadotClient` heavily relies on rxjs' `Observable`, used as well under the hood of Promise-based methods. Every method is fairly straight-forward and already documented exhaustively, except for getTypedApi. Let's dive into it. -> -> Information from: https://papi.how/client diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/bun.lockb deleted file mode 100644 index 12334da2..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/index.ts deleted file mode 100644 index b1b8a64e..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { createClient, type PolkadotClient } from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/solution/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/index.ts deleted file mode 100644 index e2eecc53..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -// TODO: Remove the "Hello via Bun!" log. -console.log("Hello via Bun!"); - -// TODO: -// - Import `getWsProvider` from `polkadot-api/ws-provider/web`. -// - import `createClient` and `type PolkadotClient` from `polkadot-api`; - -// TODO: -// - Create a new function `makeClient` -// - Function accepts a parameter `endpoint` with type `string`. -// - Function returns the `PolkadotClient` type we imported above. -// - Write the logic for `makeClient` -// - `console.log` a friendly message about which `endpoint` you are connecting to. -// - Call `getWsProvider(endpoint)`, and assign the result to a new `const provider`. -// - Call `createClient(provider)`, and assign the result to a new `const client`. -// - Return `client`. diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/connection-process/files/template/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/create-and-implement-the-printchaininfo-function.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/create-and-implement-the-printchaininfo-function.mdx deleted file mode 100644 index afd2b7eb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/create-and-implement-the-printchaininfo-function.mdx +++ /dev/null @@ -1,19 +0,0 @@ ---- -slug: create-and-implement-the-printchaininfo-function -title: Create and Implement the `printChainInfo` Function -order: 6 -last_updated: "2025-05-08" # Current date ---- - -# Create and Implement the `printChainInfo` Function - -Next, we’ll create an async function named `printChainInfo`, which will fetch and display important chain information like the chain’s name and its latest finalized block. - -Here’s what we’ll do: - -1. **Create the function:** Define an async function named printChainInfo that accepts a client parameter of type PolkadotClient. -2. Fetch the chain specifications: Inside the function, use the client.getChainSpecData() method to retrieve the chain’s specification. Don’t forget to await the result and store it in a constant named chainSpec. **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. -3. **Fetch the latest finalized block:** Next, call the `client.getFinalizedBlock()` method to get the most recently finalized block. Again, await the result and store it in a constant called finalizedBlock. -4. **Print the data:** Finally, log the chain’s name (chainSpec.name) and the finalized block number (finalizedBlock.number) in a user-friendly message. - -In the next steps, we’ll dive deeper into how to call this function and work with the fetched data. Let’s keep moving! diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/bun.lockb deleted file mode 100644 index 12334da2..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/index.ts deleted file mode 100644 index f89b0bc4..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -import process from "node:process"; - -import { createClient, type PolkadotClient } from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -async function printChainInfo(client: PolkadotClient) { - // **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. - const chain = await client.getChainSpecData(); - const finalizedBlock = await client.getFinalizedBlock(); - console.log( - `Connected to ${chain.name} at block ${finalizedBlock.number}.\n`, - ); -} - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - await printChainInfo(polkadotClient); - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/solution/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/bun.lockb deleted file mode 100644 index 12334da2..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/index.ts deleted file mode 100644 index cf0962ea..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -import process from "node:process"; - -import { createClient, type PolkadotClient } from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -// TODO: -// - Create a new `async` function` named `printChainInfo`. -// - It should accept a parameter `client` of type `PolkadotClient`. -// - Write the logic for `printChainInfo`. -// - Call the `getChainSpecData` method, which is exposed on `client`. **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. -// - `await` the result, and assign the output to a new constant `chainSpec`. -// - Call the `getFinalizedBlock` method, which is exposed on `client`. -// - `await` the result, and assign the output to a new constant `finalizedBlock`. -// - Print `chainSpec.name` and `finalizedBlock.number` with a friendly message. - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - // TODO: Replace this line with `await printChainInfo({ polkadotClient });` - console.log({ polkadotClient }); - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/create-and-implement-the-printchaininfo-function/files/template/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/bun.lockb deleted file mode 100644 index 15ba5617..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/index.ts deleted file mode 100644 index 2a5e4b80..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/index.ts +++ /dev/null @@ -1 +0,0 @@ -console.log("Hello via Bun!"); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/package.json deleted file mode 100644 index d1a196a6..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/files/source/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/initialize-a-basic-typescript-project.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/initialize-a-basic-typescript-project.mdx deleted file mode 100644 index 1fab1cfc..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/initialize-a-basic-typescript-project/initialize-a-basic-typescript-project.mdx +++ /dev/null @@ -1,74 +0,0 @@ ---- -slug: initialize-a-basic-typescript-project -title: Initialize a Basic TypeScript Project -order: 1 -last_updated: "2025-05-08" # Current date ---- - -# 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](https://bun.sh/docs/installation#installing). -> -> 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: - -```bash -$ 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): - -```shell -$ 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: - -```shell -$ bun run index.ts -``` - -You should see the following output: - -```shell -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. diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/index.ts deleted file mode 100644 index 2a5e4b80..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/index.ts +++ /dev/null @@ -1 +0,0 @@ -console.log("Hello via Bun!"); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/package.json deleted file mode 100644 index 9f2869fd..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "polkadot-api": "^1.3.2" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/files/source/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/lets-papi-this.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/lets-papi-this.mdx deleted file mode 100644 index fda35924..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/lets-papi-this/lets-papi-this.mdx +++ /dev/null @@ -1,59 +0,0 @@ ---- -slug: lets-papi-this -title: Let's PAPI this...! -order: 2 -last_updated: "2025-05-08" # Current date ---- - -# Let's PAPI this...! - -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)](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. :) - -## PAPI installation - -Of course we need, first of all, to add the `polkadot-api` dependency in our project. -Let's do that by running: - -```shell -$ 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. - -## What our examples will be - -Throughout this tutorial, we'll explore the following Polkadot API (PAPI) use cases for connecting to the network: - -1. **Connecting to the Polkadot Relay Chain:** We’ll start by using a WsProvider provided by PAPI to create a client that connects to the Polkadot relay chain's RPC server. We’ll then log the finalized block number and hash as they are produced. -2. **Connecting to the People Parachain:** Next, we’ll apply a similar approach to create a client that connects to the RPC server of the People system parachain. Here, we’ll log specific information from an account’s address. -3. **Multi-Chain Connection:** Then, we’ll set up a multi-chain connection to retrieve information from both the People and Collective system chains. - (...upcoming...) -4. **Using the Smoldot Provider:** Finally, we’ll repeat all of the above steps using the Smoldot provider that PAPI includes, allowing us to see how it compares with the WsProvider. - -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: - -- The `polkadot` relay chain -- The `people` system parachain and -- The `collectives` parachain - -## Configuring Polkadot API - -Polkadot API comes with a handy bundle of chainspecs for both [`well-known-chains` and `system-chains`](https://github.com/polkadot-api/polkadot-api/tree/main/packages/known-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. diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/bun.lockb deleted file mode 100644 index 414ec864..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/index.ts deleted file mode 100644 index 89f47f46..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/index.ts +++ /dev/null @@ -1,64 +0,0 @@ -import process from "node:process"; - -import { dot, people } from "@polkadot-api/descriptors"; -import { - createClient, - type PolkadotClient, - type SS58String, -} from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -async function printChainInfo(client: PolkadotClient) { - // **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. - const chain = await client.getChainSpecData(); - const finalizedBlock = await client.getFinalizedBlock(); - console.log( - `Connected to ${chain.name} at block ${finalizedBlock.number}.\n`, - ); -} - -async function getBalance( - polkadotClient: PolkadotClient, - address: SS58String, -): Promise { - const dotApi = polkadotClient.getTypedApi(dot); - const accountInfo = await dotApi.query.System.Account.getValue(address); - const { free, reserved } = accountInfo.data; - return free + reserved; -} - -async function getDisplayName( - peopleClient: PolkadotClient, - address: SS58String, -): Promise { - const peopleApi = peopleClient.getTypedApi(people); - const accountInfo = - await peopleApi.query.Identity.IdentityOf.getValue(address); - const displayName = accountInfo?.[0].info.display.value?.asText(); - return displayName; -} - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - await printChainInfo(polkadotClient); - - const peopleClient = makeClient("wss://polkadot-people-rpc.polkadot.io"); - await printChainInfo(peopleClient); - - const address = "15DCZocYEM2ThYCAj22QE4QENRvUNVrDtoLBVbCm5x4EQncr"; - const balance = await getBalance(polkadotClient, address); - const displayName = await getDisplayName(peopleClient, address); - console.log(`Balance of ${displayName} (${address}) is ${balance}.`); - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/solution/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/bun.lockb deleted file mode 100644 index 12334da2..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/index.ts deleted file mode 100644 index dbe7a07d..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/index.ts +++ /dev/null @@ -1,73 +0,0 @@ -import process from "node:process"; - -// TODO: Import `people` from `"@polkadot-api/descriptors"`; -import { dot } from "@polkadot-api/descriptors"; -import { - createClient, - type PolkadotClient, - type SS58String, -} from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -async function printChainInfo(client: PolkadotClient) { - // **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. - const chain = await client.getChainSpecData(); - const finalizedBlock = await client.getFinalizedBlock(); - console.log( - `Connected to ${chain.name} at block ${finalizedBlock.number}.\n`, - ); -} - -async function getBalance( - polkadotClient: PolkadotClient, - address: SS58String, -): Promise { - const dotApi = polkadotClient.getTypedApi(dot); - const accountInfo = await dotApi.query.System.Account.getValue(address); - const { free, reserved } = accountInfo.data; - return free + reserved; -} - -// TODO: -// - Create a new `async` function called `getDisplayName`: -// - It accepts two parameters: -// - `peopleClient` which is of type `PolkadotClient`. -// - `address` which is of type `SS58String`. -// - It returns a `Promise`. -// - Write the logic of the `getDisplayName` function: -// - Call the `getTypedApi` method on the `peopleClient` variable. -// - The `getTypedApi` method should include the parameter `people`, which we imported above. -// - Assign the result to a new constant `peopleApi`. -// - Call `peopleApi.query.Identity.IdentityOf.getValue(address)`. -// - `await` the result, and assign it to a new constant `accountInfo`. -// - Extract the display name with: `accountInfo?.[0].info.display.value?.asText()` -// - Assign the result to a new constant `displayName`. -// - Return the `displayName` constant. - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - await printChainInfo(polkadotClient); - - const peopleClient = makeClient("wss://polkadot-people-rpc.polkadot.io"); - await printChainInfo(peopleClient); - - const address = "15DCZocYEM2ThYCAj22QE4QENRvUNVrDtoLBVbCm5x4EQncr"; - const balance = await getBalance(polkadotClient, address); - // TODO: - // - Call `getDisplayName`, using the constants `peopleClient` and `address. - // - `await` the result, and assign it to a constant named `display`. - // - Update the message below to include the display name of the user. - console.log(`Balance of ${address} is ${balance}.`); - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/files/template/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/people-system-chain.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/people-system-chain.mdx deleted file mode 100644 index 777e6c51..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/people-system-chain/people-system-chain.mdx +++ /dev/null @@ -1,48 +0,0 @@ ---- -slug: people-system-chain -title: PEOPLE System Chain -order: 8 -last_updated: "2025-05-08" # Current date ---- - -# PEOPLE System Chain - -The People's Chain is a System chain, designed to enhance decentralized identity management and foster social interactions. This platform empowers users to control their digital identities while actively participating in community governance. - -Earlier in this tutorial, you created the `people` descriptor, which we will now utilize in the same manner as we did with the `dot` descriptor in the previous steps. - -This approach will allow us to interact with the People’s Chain effectively. - -The main query that we are interested for the People system chain is the following: - -```ts -await peopleApi.query.Identity.IdentityOf.getValue(address); -``` - -This will receive an address as an input, and return the address's holder information (`accountInfo`). - -Hint: - -```ts -[{ - judgements: [number, IdentityJudgement][]; - deposit: bigint; - info: { - display: IdentityData; - legal: IdentityData; - web: IdentityData; - ... 6 more ...; - discord: IdentityData; - }; -}, Binary | undefined] | undefined -``` - -With that information you could then retrieve the data needed (good exercise: try to follow the typed API). - -E.g.: - -```ts -accountInfo?.[0].info.display.value?.asText(); -``` - -In case a result from the query above is undefined, that means that the specific address, has not set an OnChain Identity. diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/index.ts deleted file mode 100644 index 6626bce0..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -import process from "node:process"; - -import { createClient, type PolkadotClient } from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - console.log({ polkadotClient }); - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/solution/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/index.ts deleted file mode 100644 index 00349856..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { createClient, type PolkadotClient } from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -// TODO: Create a new `async` function named `main` with the following logic: -// - Call `makeClient` with endpoint `"wss://rpc.polkadot.io"`. -// - Assign the result to a new constant named `polkadotClient`. -// - Use `console.log({ polkadotClient });` to take a peek at the methods exposed by the client. - -// TODO: Call the `main` function so it runs when executing this file. diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/files/template/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/remote-procedure-call-rpc-endpoints.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/remote-procedure-call-rpc-endpoints.mdx deleted file mode 100644 index f0ed6715..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/remote-procedure-call-rpc-endpoints/remote-procedure-call-rpc-endpoints.mdx +++ /dev/null @@ -1,27 +0,0 @@ ---- -slug: remote-procedure-call-rpc-endpoints -title: Remote Procedure Call (RPC) endpoints -order: 5 -last_updated: "2025-05-08" # Current date ---- - -# Remote Procedure Call (RPC) endpoints - -In the Polkadot ecosystem, RPC endpoints are crucial for allowing external applications, wallets, dApps, and nodes to interact with the blockchain. These endpoints provide access to the chain's functionality and data, enabling developers to query the network, submit transactions, and more. Here's an overview of what RPC endpoints are and how they function in Polkadot. - -An RPC endpoint is a URL or connection point that an application or client uses to communicate with a blockchain node. In Polkadot, RPC endpoints are generally provided by public nodes, allowing developers to interact with the blockchain without running their own full node. These endpoints offer access to the chain’s infomration such as: - -1. Blockchain state (e.g., balances, storage) -2. Runtime calls (e.g., transaction submission, governance voting) -3. Block and transaction data (e.g., querying block heights, block hashes) -4. Network data (e.g., peer information, sync status) - etc... - -In a previous step, we covered how to set up a `provider` and initialize the `client`, giving us a connection to the Polkadot network. We also introduced the `PolkadotClient` interface, which serves as the high-level API for interacting with the network through polkadot-api. - -Now, we’ll focus on two key methods from this interface that we’ll use in the upcoming steps: - -- **`getChainSpecData`**: This method retrieves the chain specification data, providing essential information about the network's configuration. **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. Reason is that chain information is not standarized on-chain yet ([RFC-8 should be implemented](https://github.com/polkadot-fellows/RFCs/blob/main/text/0008-parachain-bootnodes-dht.md) for this to happen). So as a heads up you may use this here but do NOT use in real dApps. -- **`getFinalizedBlock`**: This allows us to fetch the latest finalized block, which is useful for ensuring we're working with the most stable and confirmed state of the blockchain. - -Try to log the `polkadotClient` for this step in order to see these methods as output. diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/bun.lockb deleted file mode 100644 index 12334da2..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/index.ts deleted file mode 100644 index bbfb5a7b..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/index.ts +++ /dev/null @@ -1,49 +0,0 @@ -import process from "node:process"; - -import { dot } from "@polkadot-api/descriptors"; -import { - createClient, - type PolkadotClient, - type SS58String, -} from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -async function printChainInfo(client: PolkadotClient) { - // **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. - const chain = await client.getChainSpecData(); - const finalizedBlock = await client.getFinalizedBlock(); - console.log( - `Connected to ${chain.name} at block ${finalizedBlock.number}.\n`, - ); -} - -async function getBalance( - polkadotClient: PolkadotClient, - address: SS58String, -): Promise { - const dotApi = polkadotClient.getTypedApi(dot); - const accountInfo = await dotApi.query.System.Account.getValue(address); - const { free, reserved } = accountInfo.data; - return free + reserved; -} - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - await printChainInfo(polkadotClient); - - const address = "15DCZocYEM2ThYCAj22QE4QENRvUNVrDtoLBVbCm5x4EQncr"; - const balance = await getBalance(polkadotClient, address); - console.log(`Balance of ${address} is ${balance}.`); - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/solution/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/descriptors/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/descriptors/package.json deleted file mode 100644 index 492be0b8..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/descriptors/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.1.0-autogenerated.436979661103396732", - "name": "@polkadot-api/descriptors", - "files": [ - "dist" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "module": "./dist/index.mjs", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./package.json": "./package.json" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "browser": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "sideEffects": false, - "peerDependencies": { - "polkadot-api": "*" - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/collectives.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/collectives.scale deleted file mode 100644 index 9160e199..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/collectives.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/dot.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/dot.scale deleted file mode 100644 index 1fb4c309..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/dot.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/people.scale b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/people.scale deleted file mode 100644 index bd7d0f15..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/metadata/people.scale and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/polkadot-api.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/polkadot-api.json deleted file mode 100644 index 66080bcb..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/.papi/polkadot-api.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": 0, - "descriptorPath": ".papi/descriptors", - "entries": { - "dot": { - "chain": "polkadot", - "metadata": ".papi/metadata/dot.scale" - }, - "people": { - "chain": "polkadot_people", - "metadata": ".papi/metadata/people.scale" - }, - "collectives": { - "chain": "polkadot_collectives", - "metadata": ".papi/metadata/collectives.scale" - } - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/bun.lockb b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/bun.lockb deleted file mode 100644 index 12334da2..00000000 Binary files a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/bun.lockb and /dev/null differ diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/index.ts b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/index.ts deleted file mode 100644 index 598ad513..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/index.ts +++ /dev/null @@ -1,53 +0,0 @@ -import process from "node:process"; - -// TODO: Import the type `SS58String` from `"polkadot-api"`. -import { createClient, type PolkadotClient } from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; -// TODO: Import `dot` from `"@polkadot-api/descriptors"`. - -function makeClient(endpoint: string): PolkadotClient { - console.log(`Connecting to endpoint: ${endpoint}`); - const provider = getWsProvider(endpoint); - const client = createClient(provider); - return client; -} - -async function printChainInfo(client: PolkadotClient) { - // **IMPORTANT NOTE:** This method is used in this tutorial, but it should not be used in production apps. - const chain = await client.getChainSpecData(); - const finalizedBlock = await client.getFinalizedBlock(); - console.log( - `Connected to ${chain.name} at block ${finalizedBlock.number}.\n`, - ); -} - -// TODO: -// - Create a new `async` function called `getBalance`: -// - It accepts two parameters: -// - A parameter named `polkadotClient` which is of type `PolkadotClient`. -// - A parameter named `address` which is of type `SS58String` which we imported above. -// - It returns a `Promise`. -// - Write the logic of the `getBalance` function: -// - Call the `getTypedApi` method on the `polkadotClient` variable. -// - The `getTypedApi` method should include the parameter `dot`, which we imported above. -// - Assign the result to a new constant `dotApi`. -// - Call `dotApi.query.System.Account.getValue(address)`. -// - `await` the result, and assign it to a new constant `accountInfo`. -// - Extract the `free` and `reserved` balance from `accountInfo.data`. -// - Return the sum of `free` and `reserved`. - -async function main() { - const polkadotClient = makeClient("wss://rpc.polkadot.io"); - await printChainInfo(polkadotClient); - - // TODO: - // - Create a new constant `address` with value `"15DCZocYEM2ThYCAj22QE4QENRvUNVrDtoLBVbCm5x4EQncr"`. - // - Call `getBalance`, using the constants `polkadotClient` and `address`. - // - `await` the result, and assign it to a constant named `balance`. - // - Print a friendly message to display the `address` and their `balance`. - - console.log(`Done!`); - process.exit(0); -} - -main(); diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/package.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/package.json deleted file mode 100644 index 174c49db..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "papi-intro-tutorial", - "module": "index.ts", - "type": "module", - "scripts": { - "postinstall": "papi" - }, - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@polkadot-api/descriptors": "file:.papi/descriptors", - "polkadot-api": "^1.3.2" - } -} \ No newline at end of file diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/tsconfig.json b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/tsconfig.json deleted file mode 100644 index 238655f2..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/files/template/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} diff --git a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/some-specifics-around-papi-are-needed.mdx b/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/some-specifics-around-papi-are-needed.mdx deleted file mode 100644 index f6db3256..00000000 --- a/content/courses/papi-intro-tutorial/sections/introduction-to-the-new-polkadot-api/lessons/some-specifics-around-papi-are-needed/some-specifics-around-papi-are-needed.mdx +++ /dev/null @@ -1,84 +0,0 @@ ---- -slug: some-specifics-around-papi-are-needed -title: Some specifics around PAPI are needed -order: 7 -last_updated: "2025-05-08" # Current date ---- - -# Some specifics around PAPI are needed - -As explained in a previous step, running the `CLI` command `papi add`, downloads the metadata for a chain and then uses that metadata to generate all the type descriptors, placing them under the `.papi` directory. - -It's important to know that the descriptors exported by the codegen **should be treated as a black box**. When importing the descriptors of a chain, the type might not actually match what's in runtime, and its internals are subject to change. It has to be treated as an opaque token, passing it directly to client's method: `.getTypedApi()`. -That method returns a `TypedApi` interface. - -### TypedAPI interface - -The `TypedApi` interface, simplifies interaction with the runtime metadata, making it easy to query storage, submit transactions, and more — all while offering a smooth developer experience. - -It achieves this by utilizing the type descriptors generated by the PAPI CLI (discussed earlier), which are used to define the types available during development. - -This structure allows for seamless access to chain functionality, ensuring that everything from runtime calls to storage queries is fully typed, reducing errors and making your code more reliable. - -The structure of the TypedApi object looks like this: - -```ts -type TypedApi = { - query: StorageApi; - tx: TxApi; - event: EvApi; - apis: RuntimeCallsApi; - constants: ConstApi; - compatibilityToken: Promise; -}; -``` - -### Example of using - -In order to "access the chain functionality" as described the following code snippet can be used: - -```ts -// Import the generated descriptor -import { dot } from "@polkadot-api/descriptors"; -.... -// after creating the provider and initializing the client -// use that client to get the interface by passing the decsriptor -const dotApi = client.getTypedApi(dot); -... -// Then the strongly typed interface can be used in a sync or async -// manner depending on what needs to be called from the interface -// (deep dive into more here: https://papi.how/typed/ ) -const accountInfo = await dotApi.query.System.Account.getValue(address); -``` - -Looking at the last line, it is obvious that we are trying to query a chain's account information based on its address. - -### Breakdown of the Query: - -- **dotApi:** As mentioned, this is an instance that provides access to various modules and their methods of Polkadot chain -- **query:** This segment of the API is used to retrieve information from the blockchain without making any changes to its state. Queries are read-only operations. -- **System:** This refers to the System module, which provides foundational information about the blockchain. It includes various functionalities like querying account information, system health, and other basic parameters of the network. -- **Account:** Within the System module, the Account component allows you to interact with account-specific data. This includes balances, nonce (transaction count), and the account's state. -- **getValue(address):** This method retrieves the account information for a specific address provided as an argument. The address parameter should be a valid account identifier (either a public key or an address). - -The returned value typically includes details such as the account's free balance, reserved balance, and potentially other state data. e.g.: - -```ts -const { free, reserved } = accountInfo.data; -``` - -### Just some additional context about balances - -In Polkadot, the total balance of an account is computed as the sum of two components: free balance and reserved balance. Here's a breakdown: - -1. **Free Balance:** The free balance represents the amount of tokens that an account has available for transactions, staking, or other operations. This is the liquid balance that the user can actively spend, transfer, or use for transactions. - -2. **Reserved Balance:** The reserved balance is the portion of the account’s tokens that cannot be spent freely. Tokens may be reserved for various reasons such as bonding for staking, governance, certain on-chain operations (e.g., creating identity, reserving a slot in parachain auctions) a.k.a deposits. While the reserved balance is still owned by the account holder, it cannot be transferred or used until it's released from its reserved state. - -3. **Total Balance:** The total balance of an account is calculated as: - -``` -total_balance = free_balance + reserved_balance -``` - -This formula gives the overall account balance, but not all of it is available for transactions. The free balance is the spendable portion, while the reserved balance remains locked.