Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

docs: update readme to reflect new config DX #921

Merged
merged 21 commits into from
Apr 21, 2023
Merged
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"markdownlint.config": {
"MD013": false,
"MD024": false,
"MD033": false
}
}
114 changes: 104 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,137 @@
> 2023**.

Capi is a framework for crafting interactions with Substrate chains. It consists
of a development server and fluent API, which facilitates multistep, multichain
of a development server and fluent API, which facilitates multichain
interactions without compromising either performance or ease of use.

- [Docs &rarr;](https://docs.capi.dev)<br />Guides for Capi developers and
pattern library developers
- [Examples &rarr;](./examples)<br />SHOW ME THE CODE
- [API Reference &rarr;](https://deno.land/x/capi/mod.ts)<br />A generated API
reference, based on type signatures and TSDocs.

## Installation

### [Node.js](https://nodejs.org/)

```sh
npm i capi https://capi.dev/frame/wss/rpc.polkadot.io/@latest/pkg.tar
npm i capi
```

### [Deno](https://deno.land/)
<details >
<summary>Deno Equivalent</summary>
<br>

`import_map.json`

```json
{
"imports": {
"@capi/polkadot": "https://capi.dev/frame/wss/rpc.polkadot.io/@latest/"
"capi": "https://deno.land/x/capi/mod.ts"
}
}
```

</details>

## Configuration

Create a `capi.config.ts` and specify the chains with which you'd like to
interact.

```ts
import { CapiConfig } from "capi"

export const config: CapiConfig = {
server: "https://capi.dev/",
chains: {
polkadot: {
url: "wss://rpc.polkadot.io/",
version: "v0.9.40",
},
},
}
```

Let's also configure an ephemeral development network.
harrysolovay marked this conversation as resolved.
Show resolved Hide resolved

```diff
- import { CapiConfig } from "capi"
+ import { binary, CapiConfig } from "capi"

export const config: CapiConfig = {
server: "https://capi.dev/",
chains: {
polkadot: {
url: "wss://rpc.polkadot.io/",
version: "v0.9.40",
},
+ polkadotDev: {
+ binary: binary("polkadot", "v0.9.38"),
+ chain: "polkadot-dev",
+ },
},
}
```

## Command Line Tool

In this documentation, we use Capi's CLI via the alias "capi", instead of via
its full path:

```sh
./node_modules/.bin/capi
```

<details >
harrysolovay marked this conversation as resolved.
Show resolved Hide resolved
<summary>Deno Equivalent</summary>
<br>

```sh
deno run -A https://deno.land/x/capi/main.ts
```

</details>

## Codegen Chain-specific APIs

```sh
capi sync --package-json package.json
```

<details >
<summary>Deno Equivalent</summary>
<br>

```sh
capi sync --import-map import_map.json
```

</details>

## At a Glance

Retrieve the first 10 entries from a storage map of Polkadot.

```ts
import { System } from "@capi/polkadot"
import { chain } from "@capi/polkadot"

const accounts = await System.Account.entryPage(10, null).run()
const accounts = await chain.System.Account
.entryPage(10, null)
.run()
```

## Development Networks

To run this same example against the Polkadot development network, use the
harrysolovay marked this conversation as resolved.
Show resolved Hide resolved
`serve` command, followed by a `--` and your devnet-using command.

```sh
capi serve -- <your-command>
```

> For examples...
>
> - `capi serve -- npm run start`
> - `capi serve -- node ./main.js`
> - `capi serve -- deno run -A ./main.ts`

## Running Examples

Within a fresh clone of this repository...
Expand Down