Skip to content

Commit

Permalink
correct grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva committed Apr 8, 2024
1 parent fbd8b4e commit 590879e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
26 changes: 13 additions & 13 deletions docs/pages/codegen.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Codegen

Technically, to connect to a chain all you need is just the provider. But to interact with it you need to know the list of storage, runtime and transaction calls and their types.
Technically, to connect to a chain, all you need is just the provider. But to interact with it, you need to know the list of storage, runtime, and transaction calls and their types.

During runtime, the library can request the metadata for the chain it's connected to, and from this it generates all the codecs to interact with it, but as a developer you need to get that information beforehand.
During runtime, the library can request the metadata for the chain it's connected to, and from this, it generates all the codecs to interact with it. But as a developer, you need to get that information beforehand.

Polkadot-API has a CLI that downloads the metadata for a chain, and then uses that metadata to generate all the type descriptors.
Polkadot-API has a CLI that downloads the metadata for a chain and then uses that metadata to generate all the type descriptors.

```sh
> npx papi add --help
Expand All @@ -18,16 +18,16 @@ Arguments:
Options:
--config <filename> Source for the config file
-f, --file <filename> Source from metadata encoded file
-w, --wsUrl <URL> Source from websocket url
-w, --wsUrl <URL> Source from websocket URL
-c, --chainSpec <filename> Source from chain spec file
-n, --name <name> Source from a well-known chain (choices: "polkadot", "ksmcc3", "rococo_v2_2", "westend2")
--no-persist Do not persist the metadata as a file
-h, --help display help for command
```

`papi add` registers a new chain. It requires a key, which is the JS variable name the codegen will create, and a source (`-f`, `-w`, `-c` or `-n`). The command stores this information for later use into a configuration file `polkadot-api.json`, and then downloads a fresh metadata into a file `${key}.scale`.
`papi add` registers a new chain. It requires a key, which is the JS variable name the codegen will create, and a source (`-f`, `-w`, `-c`, or `-n`). The command stores this information for later use into a configuration file `polkadot-api.json` and then downloads the fresh metadata into a file `${key}.scale`.

You can add as many chains as you want, but each has to have a unique `key` (which must be a valid JS variable name)
You can add as many chains as you want, but each has to have a unique `key` (which must be a valid JS variable name).

The CLI can then be used to generate the type descriptors for all of the added chains through the `generate` command.

Expand All @@ -37,7 +37,7 @@ npx papi generate
npx papi
```

It's recommended to add `papi` to the `postinstall` script in package.json to have it automatically generate the code after installing:
It's recommended to add `papi` to the `postinstall` script in package.json to have it automatically generate the code after installation:

```js
{
Expand All @@ -49,7 +49,7 @@ It's recommended to add `papi` to the `postinstall` script in package.json to ha
}
```

The code is generated into a new node_modules package `@polkadot-api/descriptors`, but it's always re-exported from `papee/descriptors`.
The code is generated into a new `node_modules` package `@polkadot-api/descriptors`, but it's always re-exported from `papee/descriptors`.

:::info
Some package managers clean the `node_modules` folder after installing or removing dependencies. When that happens, run the codegen again.
Expand All @@ -67,15 +67,15 @@ The generated code contains all of the types extracted from the metadata of all
- Constants
- Every runtime call

These are consumed by `getTypedApi()`, which allows the IDE to reference any of these calls with autocompletion, etc. On runtime, it also contains the checksum of each of these calls, so that it can detect incompatibilities with the chain it's connected to.
These are consumed by `getTypedApi()`, which allows the IDE to reference any of these calls with autocompletion, etc. At runtime, it also contains the checksum of each of these calls, so that it can detect incompatibilities with the chain it's connected to.

The types are anonymous (they don't have a name in the metadata), but PolkadotAPI has a directory of well-known types for some of the most widely used Enums. If a chain is using one of these well-known types, it's also generated and exported.

In the event that there are two chains with the two well-known type that have the same name but they are different, then the key is appended at the beginning of the type. For instance, if two chains `dot` and `ksm` might have a slightly different `PreimageRequestStatus`, in that case the codegen exports `DotPreimageRequestStatus` and `KsmPreimageRequestStatus`.
In the event that there are two chains with the two well-known types that have the same name but they are different, then the key is appended at the beginning of the type. For instance, if two chains `dot` and `ksm` might have a slightly different `PreimageRequestStatus`, in that case, the codegen exports `DotPreimageRequestStatus` and `KsmPreimageRequestStatus`.

## Usage

Import from `pappe/descriptors` every chain and type that you need, then use it through `getTypedApi()`.
Import from `papee/descriptors` every chain and type that you need, then use it through `getTypedApi()`.

```ts
import {
Expand Down Expand Up @@ -115,5 +115,5 @@ const finalizedCall = await xcmSendTx.signAndSubmit(signer);
```

:::info
`getTypedApi` has nearly no cost in runtime, so it can be safely called many times.
:::
`getTypedApi` has nearly no cost at runtime, so it can be safely called many times.
:::
12 changes: 6 additions & 6 deletions docs/pages/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Get started
# Getting Started

Start by installing papee, and a chain provider of your choice.
Start by installing papee and a chain provider of your choice.

In this guide we will use `@substrate/connect` provider, which tries to connect through the extension or it fallbacks to a light client. More info about providers can be found on the next age.
In this guide, we will use the `@substrate/connect` provider, which attempts to connect through the extension or falls back to a light client. More information about providers can be found on the next page.

```sh
npm i papee @substrate/connect
Expand All @@ -19,12 +19,12 @@ Next, download the latest metadata from the chain you want to connect to and gen
# `dot` is the name we're giving to this chain (can be any JS variable name)
# `-n polkadot` specifies to download the metadata from the well-known chain polkadot
npx papi add dot -n polkadot
# Wait for latest metadata to download, then generate types:
# Wait for the latest metadata to download, then generate the types:
npx papi
```

:::info
It's a really good idea to add `papi` to the "postinstall" script in package.json, to automate generating the types after install.
It's a really good idea to add papi to the "postinstall" script in package.json to automate generating the types after installation.
:::

Now you can create a PolkadotClient with that provider:
Expand All @@ -42,7 +42,7 @@ const client = createClient(
);
```

With the `client` you can get information such as subscribing to the last block to get the latest hash:
With the `client`, you can get information such as subscribing to the last block to get the latest hash:

```ts
client.finalized$.subscribe(
Expand Down
22 changes: 11 additions & 11 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ content:
import { HomePage } from 'vocs/components'
import { KeyPoint } from './KeyPoint';

<HomePage.Root style={{}}>
<HomePage.Root>
<div className="flex justify-between w-full flex-col md:flex-row gap-4">
<div className="flex flex-col text-left">
<HomePage.Logo />
<HomePage.Description>Typescript API to interact with polkadot chains.</HomePage.Description>
<HomePage.Description>Typescript API to interact with Polkadot chains.</HomePage.Description>
<HomePage.Buttons className="py-2">
<HomePage.Button href="/getting-started" variant="accent">Get started</HomePage.Button>
<HomePage.Button href="https://github.com/polkadot-api/polkadot-api">GitHub</HomePage.Button>
Expand All @@ -23,26 +23,26 @@ import { KeyPoint } from './KeyPoint';

<div className="flex gap-2 flex-col md:flex-row mt-8">
<KeyPoint title="Light client first">
Built from the ground up for the light client, allowing running a node from the browser.
Built from the ground up for the light client, allowing the running of a node from the browser.
</KeyPoint>
<KeyPoint title="Fully typed API">
IDEs show all the type information for every operation of a chain.
</KeyPoint>
<KeyPoint title="Lightweight">
Minimal impact on the main bundle (under 50kB)
Minimal impact on the main bundle (under 50kB).
</KeyPoint>
</div>

<div className="text-left w-full max-w-2xl p-2">
<h2 className="text-[--vocs-color_heading] text-3xl py-4 border-b border-gray-500 mb-4">Features</h2>
<ul className="list-disc pl-5">
<li>Connect to the chain through a light client, a WebSocket connection, or an extension</li>
<li>Perform storage queries or runtime calls</li>
<li>Generate the types of a chain through its current metadata</li>
<li>Compatibility checks</li>
<li>Multiple connections to different chains</li>
<li>Transaction API in read-only and read/write mode</li>
<li>Promise-based or Observable-based API for your needs</li>
<li>Connect to the chain through a light client, a WebSocket connection, or an extension.</li>
<li>Perform storage queries or runtime calls.</li>
<li>Generate the types of a chain through its current metadata.</li>
<li>Compatibility checks.</li>
<li>Multiple connections to different chains.</li>
<li>Transaction API in read-only and read/write mode.</li>
<li>Promise-based or Observable-based API for your needs.</li>
</ul>
</div>
</HomePage.Root>

0 comments on commit 590879e

Please sign in to comment.