- v0.1.1-beta.1Latest
- v0.1.1-beta.0
- v0.1.0-gamma.1
- v0.1.0-gamma.0
- v0.1.0-beta.49
- v0.1.0-beta.48
- v0.1.0-beta.47
- v0.1.0-beta.46
- v0.1.0-beta.45
- v0.1.0-beta.42
- v0.1.0-beta.41
- v0.1.0-beta.40
- v0.1.0-beta.39
- v0.1.0-beta.38
- v0.1.0-beta.37
- v0.1.0-beta.36
- v0.1.0-beta.35
- v0.1.0-beta.34
- v0.1.0-beta.33
- v0.1.0-beta.32
- v0.1.0-beta.31
- v0.1.0-beta.30
- v0.1.0-beta.29
- v0.1.0-beta.28
- v0.1.0-beta.27
- v0.1.0-beta.26
- v0.1.0-beta.25
- v0.1.0-beta.24
- v0.1.0-beta.23
- v0.1.0-beta.22
- v0.1.0-beta.21
- v0.1.0-beta.20
- v0.1.0-beta.19
- v0.1.0-beta.18
- v0.1.0-beta.17
- v0.1.0-beta.16
- v0.1.0-beta.15
- v0.1.0-beta.14
- v0.1.0-beta.13
- v0.1.0-beta.12
- v0.1.0-beta.11
- v0.1.0-beta.10
- v0.1.0-beta.9
- v0.1.0-beta.8
- v0.1.0-beta.7
- v0.1.0-beta.6
- v0.1.0-beta.5
- v0.1.0-beta.4
- v0.1.0-beta.2
- v0.1.0-beta.1
Capi
Capi is a work in progress. The documentation may not reflect the current implementation. Expect a stable release and proper documentation in early 2023.
Capi is a framework for crafting interactions with Substrate chains. It consists of a development server and fluent API, which facilitates multichain interactions without compromising either performance or ease of use.
- Examples →
SHOW ME THE CODE - API Reference →
A generated API reference, based on type signatures and TSDocs.
Installation
npm i capi
Deno Equivalent
import_map.json
{
"imports": {
"capi": "https://deno.land/x/capi/mod.ts"
}
}
Configuration
Create a capi.config.ts
and specify the chains with which you’d like to
interact.
import { binary, CapiConfig } from "capi"
export const config: CapiConfig = {
server: "https://capi.dev/",
chains: {
// 1. the Polkadot relay chain
polkadot: {
url: "wss://rpc.polkadot.io/",
version: "v0.9.40",
},
// 2. a Polkadot development network
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:
./node_modules/.bin/capi
Deno Equivalent
deno run -A https://deno.land/x/capi/main.ts
Codegen Chain-specific APIs
capi sync --package-json package.json
Deno Equivalent
capi sync --import-map import_map.json
At a Glance
Retrieve the first 10 entries from a storage map of Polkadot.
import { polkadot } from "@capi/polkadot"
const accounts = await polkadot.System.Account
.entryPage(10, null)
.run()
Development Networks
Let’s modify the usage above to target our configured devnet.
- import { polkadot } from "@capi/polkadot"
+ import { polkadotDev } from "@capi/polkadot-dev"
- const accounts = await polkadot.System.Account
+ const accounts = await polkadotDev.System.Account
.entryPage(10, null)
.run()
To run code that depends on a devnet, use the serve
command, followed by a
“–” and your devnet-using command. In this case, we’ll run the script
(main.js
) with Node.JS.
capi serve -- node main.js
Other examples:
capi serve -- npm run start
capi serve -- deno run -A ./main.ts
Running Examples
Within a fresh clone of this repository…
deno task run examples/<example_file>
Rationale
In a likely future of specialized, interoperable chains, developers will need to make use of on-chain programs to satisfy varying use cases; the expertise required to interact with these on-chain programs is currently greater than that which should be expected of app developers. Does this mean that app developers must forgo integrating with this blossoming infrastructure? We think not; the open source community can use Capi to abstract over the atomics of the on-chain world. An interaction spanning several chains and dozens of methods can be described with a single Rune1.
As you read through this documentation, please consider use cases over which you might like to abstract; if you wish to add your use case to Capi’s standard library, please submit an issue.
Code of Conduct
Everyone interacting in this repo is expected to follow the code of conduct.
Contributing
Contributions are welcome and appreciated! Check out the contributing guide before you dive in.
License
Capi is Apache licensed.
Footnotes
-
Rune is the unit of composition with which we model Capi programs. ↩