polkadot-cli 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +68 -5
  2. package/dist/cli.mjs +1075 -806
  3. package/package.json +9 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # polkadot-cli
2
2
 
3
- A command-line tool for interacting with Polkadot-ecosystem chains. Manage chains and accounts, query storage, look up constants, inspect metadata, and submit extrinsics — all from your terminal.
3
+ A command-line tool for interacting with Polkadot-ecosystem chains. Manage chains and accounts, query storage, look up constants, inspect metadata, submit extrinsics, and compute hashes — all from your terminal.
4
4
 
5
5
  Ships with Polkadot as the default chain. Add any Substrate-based chain by pointing to its RPC endpoint.
6
6
 
@@ -39,6 +39,8 @@ dot chain remove westend
39
39
 
40
40
  Dev accounts (Alice, Bob, Charlie, Dave, Eve, Ferdie) are always available for testnets. Create or import your own accounts for any chain.
41
41
 
42
+ > **Security warning:** Account secrets (mnemonics and seeds) are currently stored **unencrypted** in `~/.polkadot/accounts.json`. Do not use this for high-value accounts on mainnet. Encrypted storage is planned for a future release.
43
+
42
44
  ```bash
43
45
  # List all accounts (dev + stored)
44
46
  dot account list
@@ -49,13 +51,19 @@ dot account create my-validator
49
51
  # Import from a BIP39 mnemonic
50
52
  dot account import treasury --secret "word1 word2 ... word12"
51
53
 
52
- # Import from a hex seed
53
- dot account import raw-key --secret 0xabcdef...
54
-
55
54
  # Remove an account
56
55
  dot account remove my-validator
57
56
  ```
58
57
 
58
+ **Supported secret formats for import:**
59
+
60
+ | Format | Example | Status |
61
+ |--------|---------|--------|
62
+ | BIP39 mnemonic (12/24 words) | `"abandon abandon ... about"` | Supported |
63
+ | Hex seed (`0x` + 64 hex chars) | `0xabcdef0123...` | Not supported via CLI (see below) |
64
+
65
+ **Known limitation:** Hex seed import (`--secret 0x...`) does not work from the command line. The CLI argument parser (`cac`) interprets `0x`-prefixed values as JavaScript numbers, which loses precision for 32-byte seeds. Use a BIP39 mnemonic instead. If you need to import a raw seed programmatically, write it directly to `~/.polkadot/accounts.json`.
66
+
59
67
  ### Query storage
60
68
 
61
69
  ```bash
@@ -115,6 +123,21 @@ dot tx 0x0503008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48
115
123
  dot tx Utility.batchAll '[{"type":"Balances","value":{"type":"transfer_keep_alive","value":{"dest":"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty","value":1000000000000}}},{"type":"Balances","value":{"type":"transfer_keep_alive","value":{"dest":"5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y","value":2000000000000}}}]' --from alice
116
124
  ```
117
125
 
126
+ #### Encode call data
127
+
128
+ Encode a call to hex without signing or submitting. Useful for preparing calls to pass to `Sudo.sudo`, multisig proposals, or governance. Works offline from cached metadata and does not require `--from`.
129
+
130
+ ```bash
131
+ # Encode a remark call
132
+ dot tx System.remark 0xdeadbeef --encode
133
+
134
+ # Encode a transfer (use the hex output in a batch or sudo call)
135
+ dot tx Balances.transfer_keep_alive 5FHneW46... 1000000000000 --encode
136
+
137
+ # Use encoded output with Sudo.sudo
138
+ dot tx Sudo.sudo $(dot tx System.remark 0xcafe --encode) --from alice
139
+ ```
140
+
118
141
  Both dry-run and submission display the encoded call hex and a decoded human-readable form:
119
142
 
120
143
  ```
@@ -139,6 +162,29 @@ For manual override, use `--ext` with a JSON object:
139
162
  dot tx System.remark 0xdeadbeef --from alice --ext '{"MyExtension":{"value":"..."}}'
140
163
  ```
141
164
 
165
+ ### Compute hashes
166
+
167
+ Compute cryptographic hashes commonly used in Substrate. Supports BLAKE2b-256, BLAKE2b-128, Keccak-256, and SHA-256.
168
+
169
+ ```bash
170
+ # Hash hex-encoded data
171
+ dot hash blake2b256 0xdeadbeef
172
+
173
+ # Hash plain text (UTF-8 encoded)
174
+ dot hash sha256 hello
175
+
176
+ # Hash file contents
177
+ dot hash keccak256 --file ./data.bin
178
+
179
+ # Read from stdin
180
+ echo -n "hello" | dot hash sha256 --stdin
181
+
182
+ # JSON output
183
+ dot hash blake2b256 0xdeadbeef --output json
184
+ ```
185
+
186
+ Run `dot hash` with no arguments to see all available algorithms.
187
+
142
188
  ### Global options
143
189
 
144
190
  | Flag | Description |
@@ -149,6 +195,21 @@ dot tx System.remark 0xdeadbeef --from alice --ext '{"MyExtension":{"value":"...
149
195
  | `--output json` | Raw JSON output (default: pretty) |
150
196
  | `--limit <n>` | Max entries for map queries (0 = unlimited, default: 100) |
151
197
 
198
+ ## How it compares
199
+
200
+ | | polkadot-cli | @polkadot/api-cli | subxt-cli | Pop CLI |
201
+ |---|---|---|---|---|
202
+ | **Query storage** | SS58 keys, map iteration | yes (full `--ws` URL required) | yes (keys as SCALE tuples, no SS58) | — |
203
+ | **Read constants** | yes | yes | yes | — |
204
+ | **Submit extrinsics** | yes, with dry-run | yes (via `--seed`) | — | ink! contract calls only |
205
+ | **Inspect metadata** | yes | — | yes (excellent browser) | — |
206
+ | **Chain presets** | built-in aliases (`--chain kusama`) | — (manual `--ws` every call) | — | parachain templates |
207
+ | **Tx tracking + explorer links** | spinner progress, block + explorer link | basic events | — | — |
208
+
209
+ polkadot-cli aims to be the single tool for day-to-day chain interaction: storage reads, constant lookups, transaction submission, and metadata browsing with a polished terminal UX. @polkadot/api-cli covers similar ground but is in maintenance mode and requires verbose flags. subxt-cli has an excellent metadata explorer but cannot sign or submit transactions. Pop CLI targets a different workflow — scaffolding parachains and deploying ink! contracts rather than end-user chain queries.
210
+
211
+ Outside Polkadot, the closest comparable in terms of interactive UX is [near-cli-rs](https://github.com/near/near-cli-rs) (NEAR).
212
+
152
213
  ## Configuration
153
214
 
154
215
  Config and metadata caches live in `~/.polkadot/`:
@@ -156,12 +217,14 @@ Config and metadata caches live in `~/.polkadot/`:
156
217
  ```
157
218
  ~/.polkadot/
158
219
  ├── config.json # chains and default chain
159
- ├── accounts.json # stored accounts (secrets encrypted at restcoming soon)
220
+ ├── accounts.json # stored accounts (⚠️ secrets are NOT encryptedsee below)
160
221
  └── chains/
161
222
  └── polkadot/
162
223
  └── metadata.bin # cached SCALE-encoded metadata
163
224
  ```
164
225
 
226
+ > **Warning:** `accounts.json` stores secrets (mnemonics and seeds) in **plain text**. Encrypted-at-rest storage is planned but not yet implemented. Keep appropriate file permissions (`chmod 600 ~/.polkadot/accounts.json`) and do not use this for high-value mainnet accounts.
227
+
165
228
  ## Development
166
229
 
167
230
  Requires [Bun](https://bun.sh).