# @polkadot-api/cli

Latest version **0.22.1** (published 2026-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @polkadot-api/cli
pnpm add @polkadot-api/cli
yarn add @polkadot-api/cli
bun add @polkadot-api/cli
```

Provides the commands `papi`, `polkadot-api`.

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.22.1 |
| Published | 2026-09-01 |
| First published | 2023-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 27 |
| Unpacked size | 244.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 156 |
| Author | Victor Oliva (https://github.com/voliva) |
| Maintainers | voliva, josepot |

## Links

- npm: https://www.npmjs.com/package/@polkadot-api/cli
- Repository: https://github.com/polkadot-api/polkadot-api
- npm.io page: https://npm.io/package/@polkadot-api/cli

## Dependencies (27)

- [ora](https://npm.io/package/ora.md) ^9.4.1
- [rxjs](https://npm.io/package/rxjs.md) ^7.8.2
- [execa](https://npm.io/package/execa.md) ^10.0.1
- [rollup](https://npm.io/package/rollup.md) ^4.63.1
- [read-pkg](https://npm.io/package/read-pkg.md) ^10.1.0
- [tsc-prog](https://npm.io/package/tsc-prog.md) ^2.3.0
- [commander](https://npm.io/package/commander.md) ^15.0.0
- [typescript](https://npm.io/package/typescript.md) ^6.0.3
- [@types/node](https://npm.io/package/@types/node.md) ^26.4.0
- [write-package](https://npm.io/package/write-package.md) ^7.2.0
- [fs.promises.exists](https://npm.io/package/fs.promises.exists.md) ^1.1.4
- [@polkadot-api/utils](https://npm.io/package/@polkadot-api/utils.md) 0.4.0
- [@polkadot-api/codegen](https://npm.io/package/@polkadot-api/codegen.md) 0.23.1
- [@polkadot-api/smoldot](https://npm.io/package/@polkadot-api/smoldot.md) 0.4.7
- [rollup-plugin-esbuild](https://npm.io/package/rollup-plugin-esbuild.md) ^6.2.1
- [@polkadot-api/sm-provider](https://npm.io/package/@polkadot-api/sm-provider.md) 0.3.8
- [@polkadot-api/ws-provider](https://npm.io/package/@polkadot-api/ws-provider.md) 0.9.1
- [@polkadot-api/known-chains](https://npm.io/package/@polkadot-api/known-chains.md) 0.12.3
- [@commander-js/extra-typings](https://npm.io/package/@commander-js/extra-typings.md) ^15.0.0
- [@polkadot-api/ink-contracts](https://npm.io/package/@polkadot-api/ink-contracts.md) 0.7.1
- [@polkadot-api/wasm-executor](https://npm.io/package/@polkadot-api/wasm-executor.md) ^0.2.3
- [@polkadot-api/ws-middleware](https://npm.io/package/@polkadot-api/ws-middleware.md) 0.4.1
- [@polkadot-api/substrate-client](https://npm.io/package/@polkadot-api/substrate-client.md) 0.7.0
- [@polkadot-api/json-rpc-provider](https://npm.io/package/@polkadot-api/json-rpc-provider.md) 0.2.0
- [@polkadot-api/observable-client](https://npm.io/package/@polkadot-api/observable-client.md) 0.19.1
- [@polkadot-api/substrate-bindings](https://npm.io/package/@polkadot-api/substrate-bindings.md) 0.21.1
- [@polkadot-api/metadata-compatibility](https://npm.io/package/@polkadot-api/metadata-compatibility.md) 0.7.1

## Recent versions

- 0.22.1 (latest) — 2026-09-01
- 0.22.2-canary.49bdaa9 (canary) — 2026-09-01
- 0.21.9-rc.1 (rc) — 2026-07-20
- 0.0.1-c9bb2ce3de90b7b5745189b6e3258c7cd945bb40.1.0 (next) — 2024-04-04
- 0.0.1-5f21a32c61a607b71f74693e0a46e8f69d497381.1.0 (pr-246) — 2024-01-23
- 0.0.1-097dae903cc84c0d8a6c93f39fef5e4724660825.1.0 (pr-245) — 2024-01-16
- 0.0.1-f90412d81eb4e75dd03050a8ce7ee4aee1881690.1.0 (pr-244) — 2024-01-16
- 0.0.1-5385372d2b5500605bc9e86b6dbd27cfd9c6469c.1.0 (pr-243) — 2024-01-16
- 0.0.1-e1be57e0d4bc452f101c3e64c37017f231803058.1.0 (pr-238) — 2024-01-16
- 0.0.1-1a9587dd9ccd1bd2572739a3ff81de3474fc0149.1.0 (pr-242) — 2024-01-16
- 0.0.1-a8c4f3c213c8f8c3b2e1c24500e4ea5c7f2142c7.1.0 (pr-241) — 2024-01-16
- 0.0.1-e894d16c994c9488b76ceaa4516cabcfaf1d94a0.1.0 (pr-240) — 2024-01-12
- 0.0.1-2d0e2e33524cf1d48d0feec107b24d2133c3c030.1.0 (pr-239) — 2024-01-08
- 0.0.1-248f1539f4e2c04e472a0c5dc0b982429f85c905.1.0 (pr-237) — 2024-01-07
- 0.0.1-0dc74a3df9195fb0e26e1ab223c34285d11bc4fe.1.0 (pr-236) — 2024-01-07
- … 817 more at https://npm.io/package/@polkadot-api/cli/versions

## README

# Polkadot API CLI

## Getting Started

Add a chain by using the add command

```sh
polkadot-api add ksm -n ksmcc3
```

In this example, `ksm` is the key to be used to reference this chain, `-n ksmcc3` is to source from the "well-known chain" Kusama.

Then you can run the CLI without arguments to generate the descriptor files

```sh
polkadot-api
```

Files are generated into a `@polkadot-api/descriptors` package.

## General Usage

```sh
polkadot-api --help
```

```sh
Usage: polkadot-api [options] [command]

Polkadot API CLI

Options:
  -h, --help               display help for command

Commands:
  generate [options]       Generate descriptor files
  add [options] <key>      Add a new chain spec to the list
  update [options] [keys]  Update the metadata files
  remove [options] <key>   Remove a chain spec from the list
  help [command]           display help for command
```

## Configuration file

By default, the Polkadot API configuration file is `polkadot-api.json`, located at the project's root folder. This file contains a record of the added chains, their sources, and the destination folders for each one of them.

All the arguments of the CLI accept an option `--config {file}` to use a different configuration file.

Optionally you can have this configuration in the `package.json` file, which will be added under the `polkadot-api` subpath.

## Commands

### Generate

```sh
Usage: polkadot-api generate [options]

Generate descriptor files

Options:
  --config <filename>  Source for the config file
  -k, --key <key>      Key of the descriptor to generate
  -h, --help           display help for command
```

By default, it generates the descriptor files for all of the chains defined in the config file. To generate only the ones for a specific chain, use the `-k, --key` parameter.

### Add

```sh
Usage: polkadot-api add [options] <key>

Add a new chain spec to the list

Arguments:
  key                         Key identifier for the chain spec

Options:
  --config <filename>         Source for the config file
  -f, --file <filename>       Source from metadata encoded file
  -w, --wsUrl <URL>           Source from websocket url
  -c, --chainSpec <filename>  Source from chain spec file
  -n, --name <name>           Source from a well-known chain
  --no-persist                Do not persist the metadata as a file
  -h, --help                  display help for command
```

This command requires one of the options to specify a source:

- From a SCALE-encoded metadata file: `-f, --file`
- From a Websocket URL: `-w, --wsUrl`
- From a chainSpect: `-c, --chainSpec`
- From a well-known chain (as of this writing: polkadot, ksmcc3, rococo_v2_2 or westend2): `-n, --name`

For the external sources (`-w`, `-c` and `-n`), the CLI automatically downloads the metadata and stores it as a file `{key}.scale` so that it can be added to source control, which is recommended. In case you want to re-fetch in on the fly every time you generate the descriptors, there's the option `--no-persist` which wil not create the metadata file.

### Update

```sh
Usage: polkadot-api update [options] [keys]

Update the metadata files

Arguments:
  keys                 Keys of the metadata files to update, separated by commas. Leave
                       empty for all

Options:
  --config <filename>  Source for the config file
  -h, --help           display help for command
```

For the chains with both an external source (added with `-w`, `-c` or `-n`) and a persisted file it re-fetches the metadata and updates the encoded metadata file.

### Remove

```sh
Usage: polkadot-api remove [options] <key>

Remove a chain spec from the list

Arguments:
  key                  Key identifier for the chain spec

Options:
  --config <filename>  Source for the config file
  -h, --help           display help for command
```

Removes the specified chain spec from the list. Equivalent as manually removing the entry from the config file.

---
_Source: https://npm.io/package/@polkadot-api/cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
