npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

capi

v0.1.1-beta.1

Published

Capi is a framework for crafting interactions with Substrate chains

Downloads

127

Readme

Capi

Announcing Capi v0.1.0-gamma.0

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.

Installation

npm i capi

Note: The minimum supported Node version is 20, as we require the Web Crypto API be accessible from globalThis.crypto for the sake of browser compatibility.

import_map.json

{
  "imports": {
    "capi": "https://deno.land/x/capi/mod.ts",
    "capi/nets": "https://deno.land/x/capi/nets/mod.ts"
  }
}

Note: For now, we only support the latest 1.x version of Deno.

Configuration

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

import { bins, net } from "capi/nets"

const bin = bins({ polkadot: ["polkadot", "v0.9.38"] })

// A Polkadot development network
export const polkadotDev = net.dev({
  bin: bin.polkadot,
  chain: "polkadot-dev",
})

// The Polkadot relay chain
export const polkadot = net.ws({
  url: "wss://rpc.polkadot.io/",
  targets: { dev: polkadotDev },
})

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 run -A https://deno.land/x/capi/main.ts

Codegen Chain-specific APIs

capi sync node
capi sync deno

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.entries({ limit: 10 }).run()

Development Networks

During development, we may want to swap out the underlying connection with that of a devnet. This can be achieved via targets — by specifying alternate targets in your nets.ts file, you can switch to them by wrapping your command with capi serve --target someTarget --. For example:

capi serve --target dev -- node main.js

Other examples:

  • capi serve --target dev -- npm run start
  • capi serve --target dev -- deno run -A ./main.ts

Running Examples

Within a fresh clone of this repository...

deno task sync # only needed once
deno task run examples/<example_path>

Or, to run an example with Node:

deno task sync # only needed once
deno task dnt --examples # only needed once
deno task capi serve -- node target/npm/capi-examples/esm/examples/<example_path>

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 Rune[^1].

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.

[^1]: Rune is the unit of composition with which we model Capi programs.