dedot 0.0.1-alpha.35 → 0.0.1-alpha.37

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 (2) hide show
  1. package/README.md +26 -39
  2. package/package.json +17 -11
package/README.md CHANGED
@@ -5,6 +5,7 @@ A delightful JavaScript/TypeScript client for [Polkadot](https://polkadot.networ
5
5
  <p align="left">
6
6
  <img src="https://img.shields.io/github/license/dedotdev/dedot?style=flat-square"/>
7
7
  <img src="https://img.shields.io/github/actions/workflow/status/dedotdev/dedot/run-tests.yml?label=unit%20tests&style=flat-square"/>
8
+ <img src="https://img.shields.io/github/actions/workflow/status/dedotdev/dedot/zombienet-tests.yml?label=e2e%20tests&style=flat-square"/>
8
9
  <img src="https://img.shields.io/github/package-json/v/dedotdev/dedot?filename=packages%2Fapi%2Fpackage.json&style=flat-square"/>
9
10
  </p>
10
11
 
@@ -22,6 +23,8 @@ _Note: The project is still in active development phase, the information on this
22
23
  - ✅ Build on top of both the [new](https://paritytech.github.io/json-rpc-interface-spec/introduction.html) & legacy (deprecated soon) JSON-RPC APIs
23
24
  - ✅ Support light clients (e.g: [smoldot](https://www.npmjs.com/package/smoldot)) (_docs coming soon_)
24
25
  - ✅ Typed Contract APIs (_docs coming soon_)
26
+ - ✅ Fully-typed low-level JSON-RPC client (_docs coming soon_)
27
+ - ⏳ [Compact Metadata](https://github.com/dedotdev/dedot/issues/45)
25
28
 
26
29
  ### Have a quick taste
27
30
 
@@ -29,19 +32,19 @@ Try `dedot` now on [CodeSandbox Playground](https://codesandbox.io/p/devbox/tryd
29
32
  - Install `dedot` package
30
33
  ```shell
31
34
  # via yarn
32
- yarn add dedot
35
+ yarn add dedot@latest
33
36
 
34
37
  # via npm
35
- npm i dedot
38
+ npm i dedot@latest
36
39
  ```
37
40
 
38
41
  - Install `@dedot/chaintypes` package for chain types & APIs suggestion. Skip this step if you don't use TypeScript.
39
42
  ```shell
40
43
  # via yarn
41
- yarn add -D @dedot/chaintypes
44
+ yarn add -D @dedot/chaintypes@latest
42
45
 
43
46
  # via npm
44
- npm i -D @dedot/chaintypes
47
+ npm i -D @dedot/chaintypes@latest
45
48
  ```
46
49
 
47
50
  - Initialize the API client and start interacting with Polkadot network
@@ -113,34 +116,17 @@ const api = await LegacyClient.new(provider);
113
116
  - [`@polkadot/api` -> `dedot`](#migration-from-polkadotapi-to-dedot)
114
117
  - [Credit](#credit)
115
118
 
116
- ### Status
117
-
118
- | Feature | Status |
119
- |-------------------------------------------------------------|--------|
120
- | Execute RPC (`api.rpc`) | ✅ |
121
- | Query On-chain Storage (`api.query`) | ✅ |
122
- | Get runtime constants (`api.consts`) | ✅ |
123
- | Runtime APIs (`api.call`) | ✅ |
124
- | Transaction APIs (`api.tx`) | ✅ |
125
- | Events (`api.events`) | ✅ |
126
- | Errors (`api.errors`) | ✅ |
127
- | Contract APIs | ✅ |
128
- | Metadata v14 | ✅ |
129
- | Metadata v15 | ✅ |
130
- | [RPC v2](https://github.com/dedotdev/dedot/issues/20) | ✅ |
131
- | [Extrinsic V5](https://github.com/dedotdev/dedot/issues/55) | ⏳ |
132
-
133
119
  ### Chain Types & APIs
134
120
 
135
121
  Each Substrate-based blockchain has their own set of data types & APIs to interact with, so being aware of those types & APIs when working with a blockchain will greatly improve the overall development experience. `dedot` exposes TypeScript's types & APIs for each individual Substrate-based blockchain, we recommend using TypeScript for your project to have the best experience.
136
122
 
137
- Types & APIs for each Substrate-based blockchains are defined in package [`@dedot/chaintypes`](https://github.com/dedotdev/dedot/tree/main/packages/chaintypes):
123
+ Types & APIs for each Substrate-based blockchains are defined in package [`@dedot/chaintypes`](https://github.com/dedotdev/chaintypes):
138
124
  ```shell
139
125
  # via yarn
140
- yarn add -D @dedot/chaintypes
126
+ yarn add -D @dedot/chaintypes@latest
141
127
 
142
128
  # via npm
143
- npm i -D @dedot/chaintypes
129
+ npm i -D @dedot/chaintypes@latest
144
130
  ```
145
131
 
146
132
  Initialize a `DedotClient` instance using the `ChainApi` interface for a target chain to enable types & APIs suggestion/autocompletion for that particular chain:
@@ -168,7 +154,7 @@ const genericApi = await DedotClient.new(new WsProvider('ws://localhost:9944'));
168
154
  // ...
169
155
  ```
170
156
 
171
- Supported `ChainApi` interfaces are defined [here](https://github.com/dedotdev/dedot/blob/main/packages/chaintypes/src/index.ts), you can also generate the `ChainApi` interface for the chain you want to connect with using `dedot` cli.
157
+ Supported `ChainApi` interfaces are defined [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/index.ts), you can also generate the `ChainApi` interface for the chain you want to connect with using `dedot` cli.
172
158
 
173
159
  ```shell
174
160
  # Generate ChainApi interface for Polkadot network via rpc endpoint: wss://rpc.polkadot.io
@@ -177,7 +163,7 @@ npx dedot chaintypes -w wss://rpc.polkadot.io
177
163
 
178
164
  ### Execute RPC Methods
179
165
 
180
- RPCs can be executed via `api.rpc` entry point. After creating a `Dedot` instance with a `ChainApi` interface of the network you want to interact with, all RPC methods of the network will be exposed in the autocompletion/suggestion with format: `api.rpc.method_name(param1, param2, ...)`. E.g: you can find all supported RPC methods for Polkadot network [here](https://github.com/dedotdev/dedot/blob/main/packages/chaintypes/src/polkadot/rpc.d.ts), similarly for other networks as well.
166
+ RPCs can be executed via `api.rpc` entry point. After creating a `Dedot` instance with a `ChainApi` interface of the network you want to interact with, all RPC methods of the network will be exposed in the autocompletion/suggestion with format: `api.rpc.method_name(param1, param2, ...)`. E.g: you can find all supported RPC methods for Polkadot network [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/json-rpc.d.ts), similarly for other networks as well.
181
167
 
182
168
  Examples:
183
169
  ```typescript
@@ -190,7 +176,7 @@ const result = await api.rpc.module_rpc_name('param1', 'param2');
190
176
 
191
177
  ### Query On-chain Storage
192
178
 
193
- On-chain storage can be queried via `api.query` entry point. All the available storage entries for a chain are exposed in the `ChainApi` interface for that chain and can be executed with format: `api.query.<pallet>.<storgeEntry>`. E.g: You can find all the available storage queries of Polkadot network [here](https://github.com/dedotdev/dedot/blob/main/packages/chaintypes/src/polkadot/query.d.ts), similarly for other networks as well.
179
+ On-chain storage can be queried via `api.query` entry point. All the available storage entries for a chain are exposed in the `ChainApi` interface for that chain and can be executed with format: `api.query.<pallet>.<storgeEntry>`. E.g: You can find all the available storage queries of Polkadot network [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/query.d.ts), similarly for other networks as well.
194
180
 
195
181
  Examples:
196
182
  ```typescript
@@ -202,7 +188,7 @@ const events = await api.query.system.events();
202
188
  ```
203
189
  ### Constants
204
190
 
205
- Runtime constants (parameter types) are defined in metadata, and can be inspected via `api.consts` entry point with format: `api.consts.<pallet>.<constantName>`. All available constants are also exposed in the `ChainApi` interface. E.g: Available constants for Polkadot network is defined [here](https://github.com/dedotdev/dedot/blob/main/packages/chaintypes/src/polkadot/consts.d.ts), similarly for other networks.
191
+ Runtime constants (parameter types) are defined in metadata, and can be inspected via `api.consts` entry point with format: `api.consts.<pallet>.<constantName>`. All available constants are also exposed in the `ChainApi` interface. E.g: Available constants for Polkadot network is defined [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/consts.d.ts), similarly for other networks.
206
192
 
207
193
  Examples:
208
194
  ```typescript
@@ -215,7 +201,7 @@ const existentialDeposit = api.consts.balances.existentialDeposit;
215
201
 
216
202
  ### Runtime APIs
217
203
 
218
- The latest stable Metadata V15 now includes all the runtime apis type information. So for chains that are supported Metadata V15, we can now execute all available runtime apis with syntax `api.call.<runtimeApi>.<methodName>`, those apis are exposed in `ChainApi` interface. E.g: Runtime Apis for Polkadot network is defined [here](https://github.com/dedotdev/dedot/blob/main/packages/chaintypes/src/polkadot/runtime.d.ts), similarly for other networks as well.
204
+ The latest stable Metadata V15 now includes all the runtime apis type information. So for chains that are supported Metadata V15, we can now execute all available runtime apis with syntax `api.call.<runtimeApi>.<methodName>`, those apis are exposed in `ChainApi` interface. E.g: Runtime Apis for Polkadot network is defined [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/runtime.d.ts), similarly for other networks as well.
219
205
 
220
206
  Examples:
221
207
  ```typescript
@@ -230,7 +216,7 @@ const queryInfo = await api.call.transactionPaymentApi.queryInfo(tx.toU8a(), tx.
230
216
  const runtimeVersion = await api.call.core.version();
231
217
  ```
232
218
 
233
- For chains that only support Metadata V14, we need to bring in the Runtime Api definitions when initializing the DedotClient instance to encode & decode the calls. You can find all supported Runtime Api definitions in [`dedot/runtime-specs`](https://github.com/dedotdev/dedot/blob/60de0fed8ba19c67a7e174c6168a127fdbf6caef/packages/runtime-specs/src/runtime/all.ts#L21-L39) package.
219
+ For chains that only support Metadata V14, we need to bring in the Runtime Api definitions when initializing the DedotClient instance to encode & decode the calls. You can find all supported Runtime Api definitions in [`dedot/runtime-specs`](https://github.com/dedotdev/dedot/blob/fefe71cf4a04d1433841f5cfc8400a1e2a8db112/packages/runtime-specs/src/all.ts#L21-L39) package.
234
220
 
235
221
  Examples:
236
222
  ```typescript
@@ -245,13 +231,13 @@ const api = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwor
245
231
  const nonce = await api.call.accountNonceApi.accountNonce(<address>);
246
232
  ```
247
233
 
248
- You absolutely can define your own Runtime Api definition if you don't find it in the [supported list](https://github.com/dedotdev/dedot/blob/60de0fed8ba19c67a7e174c6168a127fdbf6caef/packages/runtime-specs/src/runtime/all.ts#L21-L39).
234
+ You absolutely can define your own Runtime Api definition if you don't find it in the [supported list](https://github.com/dedotdev/dedot/blob/fefe71cf4a04d1433841f5cfc8400a1e2a8db112/packages/runtime-specs/src/all.ts#L21-L39).
249
235
 
250
236
  ### Transaction APIs
251
237
 
252
238
  Transaction apis are designed to be compatible with [`IKeyringPair`](https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/types/src/types/interfaces.ts#L15-L21) and [`Signer`](https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/types/src/types/extrinsic.ts#L135-L150) interfaces, so you can sign the transactions with accounts created by a [`Keyring`](https://github.com/polkadot-js/common/blob/22aab4a4e62944a2cf8c885f50be2c1b842813ec/packages/keyring/src/keyring.ts#L41-L40) or from any [Polkadot{.js}-based](https://github.com/polkadot-js/extension?tab=readme-ov-file#api-interface) wallet extensions.
253
239
 
254
- All transaction apis are exposed in `ChainApi` interface and can be access with syntax: `api.tx.<pallet>.<transactionName>`. E.g: Available transaction apis for Polkadot network are defined [here](https://github.com/dedotdev/dedot/blob/516c5dd948ac89ef53644b7fb1f62df1727adadb/packages/chaintypes/src/polkadot/tx.d.ts), similarly for other networks as well.
240
+ All transaction apis are exposed in `ChainApi` interface and can be access with syntax: `api.tx.<pallet>.<transactionName>`. E.g: Available transaction apis for Polkadot network are defined [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/tx.d.ts), similarly for other networks as well.
255
241
 
256
242
  Example 1: Sign transaction with a Keying account
257
243
  ```typescript
@@ -266,7 +252,7 @@ const unsub = await api.tx.balances
266
252
  .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
267
253
  .signAndSend(alice, async ({ status }) => {
268
254
  console.log('Transaction status', status.type);
269
- if (status.type === 'InBlock') {
255
+ if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
270
256
  console.log(`Transaction completed at block hash ${status.value}`);
271
257
  await unsub();
272
258
  }
@@ -283,7 +269,7 @@ const unsub = await api.tx.balances
283
269
  .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
284
270
  .signAndSend(account.address, { signer }, async ({ status }) => {
285
271
  console.log('Transaction status', status.type);
286
- if (status.type === 'InBlock') {
272
+ if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
287
273
  console.log(`Transaction completed at block hash ${status.value}`);
288
274
  await unsub();
289
275
  }
@@ -312,7 +298,7 @@ const remarkCall: PolkadotRuntimeRuntimeCallLike = {
312
298
  const unsub = api.tx.utility.batch([transferTx.call, remarkCall])
313
299
  .signAndSend(account.address, { signer }, async ({ status }) => {
314
300
  console.log('Transaction status', status.type);
315
- if (status.type === 'InBlock') {
301
+ if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
316
302
  console.log(`Transaction completed at block hash ${status.value}`);
317
303
  await unsub();
318
304
  }
@@ -382,7 +368,7 @@ api.tx.polkadotXcm
382
368
 
383
369
  ### Events
384
370
 
385
- Events for each pallet emit during runtime operations and are defined in the medata. Available events are also exposed in `ChainApi` interface so we can get information of an event through syntax `api.events.<pallet>.<eventName>`. E.g: Events for Polkadot network can be found [here](https://github.com/dedotdev/dedot/blob/main/packages/chaintypes/src/polkadot/events.d.ts), similarly for other network as well.
371
+ Events for each pallet emit during runtime operations and are defined in the medata. Available events are also exposed in `ChainApi` interface so we can get information of an event through syntax `api.events.<pallet>.<eventName>`. E.g: Events for Polkadot network can be found [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/events.d.ts), similarly for other network as well.
386
372
 
387
373
  This `api.events` is helpful when we want quickly check if an event matches with an event that we're expecting in a list of events, the API also comes with type narrowing for the matched event, so event name & related data of the event are fully typed.
388
374
 
@@ -406,7 +392,7 @@ await api.query.system.events(async (eventRecords) => {
406
392
 
407
393
  ### Errors
408
394
 
409
- Pallet errors are thrown out when things go wrong in the runtime, those are defined in the metadata. Available errors for each pallet are also exposed in `ChainApi` interface, so we can get information an error through this syntax: `api.errors.<pallet>.<errorName>`. E.g: Available errors for Polkadot network can be found [here](https://github.com/dedotdev/dedot/blob/main/packages/chaintypes/src/polkadot/errors.d.ts).
395
+ Pallet errors are thrown out when things go wrong in the runtime, those are defined in the metadata. Available errors for each pallet are also exposed in `ChainApi` interface, so we can get information an error through this syntax: `api.errors.<pallet>.<errorName>`. E.g: Available errors for Polkadot network can be found [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/errors.d.ts).
410
396
 
411
397
  Similar to events API, this API is helpful when we want to check if an error maches with an error that we're expecting.
412
398
 
@@ -417,7 +403,7 @@ await api.query.system.events(async (eventRecords) => {
417
403
  for (const tx of eventRecords) {
418
404
  if (api.events.system.ExtrinsicFailed.is(tx.event)) {
419
405
  const { dispatchError } = tx.event.palletEvent.data;
420
- if (dispatchError.type === 'Module' && api.errors.assets.AlreadyExists.is(dispatchError.value)) {
406
+ if (api.errors.assets.AlreadyExists.is(dispatchError)) {
421
407
  console.log('Assets.AlreadyExists error occurred!');
422
408
  } else {
423
409
  console.log('Other error occurred', dispatchError);
@@ -454,7 +440,8 @@ const api = await DedotClient.new<PolkadotApi>({ provider: new WsProvider('wss:/
454
440
 
455
441
  - Notes:
456
442
  - `dedot` only supports provider can make subscription request (e.g: via Websocket).
457
- - We recommend specifying the `ChainApi` interface (e.g: [`PolkadotApi`](https://github.com/dedotdev/dedot/blob/02d7bca4c3c3d12c9591ea43b3410daf8e5aacbb/packages/chaintypes/src/polkadot/index.d.ts) in the example above) of the chain that you want to interact with. This enable apis & types suggestion/autocompletion for that particular chain (via IntelliSense). If you don't specify a `ChainApi` interface, the default [`SubstrateApi`](https://github.com/dedotdev/dedot/blob/a762faf8f6af40d3e4ef163bd538b270a5ca31e8/packages/chaintypes/src/substrate/index.d.ts) interface will be used.
443
+ - We recommend specifying the `ChainApi` interface (e.g: [`PolkadotApi`](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/index.d.ts) in the example above) of the chain that you want to interact with. This enable apis & types suggestion/autocompletion for that particular chain (via IntelliSense). If you don't specify a `ChainApi` interface, the default [`SubstrateApi`](https://github.com/dedotdev/dedot/blob/a762faf8f6af40d3e4ef163bd538b270a5ca31e8/packages/chaintypes/src/substrate/index.d.ts) interface will be used.
444
+ - `WsProvider` from `dedot` and `@polkadot/api` are different, they cannot be used interchangeable.
458
445
 
459
446
  **Type system**
460
447
 
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "dedot",
3
- "version": "0.0.1-alpha.35",
3
+ "version": "0.0.1-alpha.37",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
+ "homepage": "https://github.com/dedotdev/dedot",
7
+ "repository": {
8
+ "directory": "packages/dedot",
9
+ "type": "git",
10
+ "url": "https://github.com/dedotdev/dedot.git"
11
+ },
6
12
  "main": "./cjs/index.js",
7
13
  "bin": {
8
14
  "dedot": "./bin/dedot",
@@ -15,15 +21,15 @@
15
21
  "clean": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo ./tsconfig.build.tsbuildinfo"
16
22
  },
17
23
  "dependencies": {
18
- "@dedot/api": "0.0.1-alpha.35",
19
- "@dedot/cli": "0.0.1-alpha.35",
20
- "@dedot/codecs": "0.0.1-alpha.35",
21
- "@dedot/contracts": "0.0.1-alpha.35",
22
- "@dedot/providers": "0.0.1-alpha.35",
23
- "@dedot/runtime-specs": "0.0.1-alpha.35",
24
- "@dedot/shape": "0.0.1-alpha.35",
25
- "@dedot/types": "0.0.1-alpha.35",
26
- "@dedot/utils": "0.0.1-alpha.35"
24
+ "@dedot/api": "0.0.1-alpha.37",
25
+ "@dedot/cli": "0.0.1-alpha.37",
26
+ "@dedot/codecs": "0.0.1-alpha.37",
27
+ "@dedot/contracts": "0.0.1-alpha.37",
28
+ "@dedot/providers": "0.0.1-alpha.37",
29
+ "@dedot/runtime-specs": "0.0.1-alpha.37",
30
+ "@dedot/shape": "0.0.1-alpha.37",
31
+ "@dedot/types": "0.0.1-alpha.37",
32
+ "@dedot/utils": "0.0.1-alpha.37"
27
33
  },
28
34
  "exports": {
29
35
  ".": {
@@ -86,7 +92,7 @@
86
92
  "directory": "dist"
87
93
  },
88
94
  "license": "Apache-2.0",
89
- "gitHead": "bf954b82ac4c8a8e1d989c0c708a099269eb4262",
95
+ "gitHead": "6ed023a9455476d39ef810da46928b3f05621879",
90
96
  "module": "./index.js",
91
97
  "types": "./index.d.ts"
92
98
  }