Skip to main content

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 declarative, TypeScript-first toolkit for crafting interactions with Substrate-based chains. It consists of FRAME utilities, a functional effect system (Rune) and a fluent API, which facilitates multistep, multichain interactions without compromising either performance or safety.

At a Glance

Run the local server.

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

Then, open your IDE and import pallet-corresponding modules from the local server.

import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/mod.ts"

const key = System.Account.keys().first()

const value = System.Account.entry(key)

console.log(await value.run())

Import Mapping

For simplicity, we recommend aliasing import specifiers via import maps.

import_map.json

{
  "imports": {
    "#polkadot/": "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/"
  }
}
- import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/mod.ts"
+ import { System } from "#polkadot/mod.ts"

Examples

See the examples/ directory.

git clone https://github.com/partitytech/capi
cd capi
deno task run codegen # host the server locally and cache all codegen
deno task run examples/<example-name>.ts

The Thesis

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 effect.

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.