dedot 0.0.1-next.fecbe32d.13 → 0.1.0

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 (152) hide show
  1. package/README.md +80 -86
  2. package/bin/dedot +3 -0
  3. package/chaintypes/index.d.ts +1 -1
  4. package/chaintypes/index.js +1 -1
  5. package/cjs/chaintypes/index.js +1 -1
  6. package/cjs/{json-rpc → codecs}/index.js +1 -1
  7. package/cjs/{storage → contracts}/index.js +1 -1
  8. package/cjs/index.js +6 -15
  9. package/cjs/runtime-specs/index.js +17 -0
  10. package/cjs/{chaintypes/substrate → shape}/index.js +1 -1
  11. package/cjs/{client → types}/index.js +1 -1
  12. package/cjs/types/json-rpc/index.js +17 -0
  13. package/cjs/utils/index.js +17 -0
  14. package/codecs/index.d.ts +1 -0
  15. package/codecs/index.js +1 -0
  16. package/contracts/index.d.ts +1 -0
  17. package/contracts/index.js +1 -0
  18. package/index.d.ts +2 -9
  19. package/index.js +2 -9
  20. package/package.json +76 -36
  21. package/runtime-specs/index.d.ts +1 -0
  22. package/runtime-specs/index.js +1 -0
  23. package/shape/index.d.ts +1 -0
  24. package/shape/index.js +1 -0
  25. package/types/index.d.ts +1 -0
  26. package/types/index.js +1 -0
  27. package/types/json-rpc/index.d.ts +1 -0
  28. package/types/json-rpc/index.js +1 -0
  29. package/utils/index.d.ts +1 -0
  30. package/utils/index.js +1 -0
  31. package/chaintypes/substrate/consts.d.ts +0 -1971
  32. package/chaintypes/substrate/consts.js +0 -1
  33. package/chaintypes/substrate/errors.d.ts +0 -3337
  34. package/chaintypes/substrate/errors.js +0 -1
  35. package/chaintypes/substrate/events.d.ts +0 -4777
  36. package/chaintypes/substrate/events.js +0 -1
  37. package/chaintypes/substrate/index.d.ts +0 -18
  38. package/chaintypes/substrate/index.js +0 -1
  39. package/chaintypes/substrate/json-rpc.d.ts +0 -3
  40. package/chaintypes/substrate/json-rpc.js +0 -1
  41. package/chaintypes/substrate/query.d.ts +0 -3447
  42. package/chaintypes/substrate/query.js +0 -1
  43. package/chaintypes/substrate/runtime.d.ts +0 -708
  44. package/chaintypes/substrate/runtime.js +0 -1
  45. package/chaintypes/substrate/tx.d.ts +0 -8800
  46. package/chaintypes/substrate/tx.js +0 -1
  47. package/chaintypes/substrate/types.d.ts +0 -20332
  48. package/chaintypes/substrate/types.js +0 -1
  49. package/cjs/chaintypes/substrate/consts.js +0 -2
  50. package/cjs/chaintypes/substrate/errors.js +0 -2
  51. package/cjs/chaintypes/substrate/events.js +0 -2
  52. package/cjs/chaintypes/substrate/json-rpc.js +0 -2
  53. package/cjs/chaintypes/substrate/query.js +0 -2
  54. package/cjs/chaintypes/substrate/runtime.js +0 -2
  55. package/cjs/chaintypes/substrate/tx.js +0 -2
  56. package/cjs/chaintypes/substrate/types.js +0 -2
  57. package/cjs/client/BaseSubstrateClient.js +0 -247
  58. package/cjs/client/Dedot.js +0 -257
  59. package/cjs/executor/ConstantExecutor.js +0 -20
  60. package/cjs/executor/ErrorExecutor.js +0 -46
  61. package/cjs/executor/EventExecutor.js +0 -52
  62. package/cjs/executor/Executor.js +0 -45
  63. package/cjs/executor/RuntimeApiExecutor.js +0 -113
  64. package/cjs/executor/StorageQueryExecutor.js +0 -109
  65. package/cjs/executor/TxExecutor.js +0 -158
  66. package/cjs/executor/index.js +0 -23
  67. package/cjs/extrinsic/SubmittableResult.js +0 -33
  68. package/cjs/extrinsic/extensions/ExtraSignedExtension.js +0 -87
  69. package/cjs/extrinsic/extensions/SignedExtension.js +0 -41
  70. package/cjs/extrinsic/extensions/index.js +0 -19
  71. package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +0 -43
  72. package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +0 -16
  73. package/cjs/extrinsic/extensions/known/CheckGenesis.js +0 -19
  74. package/cjs/extrinsic/extensions/known/CheckMortality.js +0 -70
  75. package/cjs/extrinsic/extensions/known/CheckNonZeroSender.js +0 -10
  76. package/cjs/extrinsic/extensions/known/CheckNonce.js +0 -33
  77. package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +0 -19
  78. package/cjs/extrinsic/extensions/known/CheckTxVersion.js +0 -19
  79. package/cjs/extrinsic/extensions/known/CheckWeight.js +0 -10
  80. package/cjs/extrinsic/extensions/known/PrevalidateAttests.js +0 -11
  81. package/cjs/extrinsic/extensions/known/index.js +0 -25
  82. package/cjs/extrinsic/index.js +0 -18
  83. package/cjs/json-rpc/JsonRpcClient.js +0 -157
  84. package/cjs/proxychain.js +0 -27
  85. package/cjs/storage/QueryableStorage.js +0 -161
  86. package/cjs/types.js +0 -2
  87. package/client/BaseSubstrateClient.d.ts +0 -65
  88. package/client/BaseSubstrateClient.js +0 -242
  89. package/client/Dedot.d.ts +0 -130
  90. package/client/Dedot.js +0 -253
  91. package/client/index.d.ts +0 -1
  92. package/client/index.js +0 -1
  93. package/executor/ConstantExecutor.d.ts +0 -11
  94. package/executor/ConstantExecutor.js +0 -16
  95. package/executor/ErrorExecutor.d.ts +0 -11
  96. package/executor/ErrorExecutor.js +0 -42
  97. package/executor/EventExecutor.d.ts +0 -11
  98. package/executor/EventExecutor.js +0 -48
  99. package/executor/Executor.d.ts +0 -150
  100. package/executor/Executor.js +0 -41
  101. package/executor/RuntimeApiExecutor.d.ts +0 -19
  102. package/executor/RuntimeApiExecutor.js +0 -109
  103. package/executor/StorageQueryExecutor.d.ts +0 -13
  104. package/executor/StorageQueryExecutor.js +0 -105
  105. package/executor/TxExecutor.d.ts +0 -48
  106. package/executor/TxExecutor.js +0 -152
  107. package/executor/index.d.ts +0 -7
  108. package/executor/index.js +0 -7
  109. package/extrinsic/SubmittableResult.d.ts +0 -19
  110. package/extrinsic/SubmittableResult.js +0 -29
  111. package/extrinsic/extensions/ExtraSignedExtension.d.ts +0 -14
  112. package/extrinsic/extensions/ExtraSignedExtension.js +0 -60
  113. package/extrinsic/extensions/SignedExtension.d.ts +0 -40
  114. package/extrinsic/extensions/SignedExtension.js +0 -37
  115. package/extrinsic/extensions/index.d.ts +0 -3
  116. package/extrinsic/extensions/index.js +0 -3
  117. package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +0 -14
  118. package/extrinsic/extensions/known/ChargeAssetTxPayment.js +0 -39
  119. package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +0 -6
  120. package/extrinsic/extensions/known/ChargeTransactionPayment.js +0 -12
  121. package/extrinsic/extensions/known/CheckGenesis.d.ts +0 -10
  122. package/extrinsic/extensions/known/CheckGenesis.js +0 -15
  123. package/extrinsic/extensions/known/CheckMortality.d.ts +0 -15
  124. package/extrinsic/extensions/known/CheckMortality.js +0 -66
  125. package/extrinsic/extensions/known/CheckNonZeroSender.d.ts +0 -6
  126. package/extrinsic/extensions/known/CheckNonZeroSender.js +0 -6
  127. package/extrinsic/extensions/known/CheckNonce.d.ts +0 -10
  128. package/extrinsic/extensions/known/CheckNonce.js +0 -29
  129. package/extrinsic/extensions/known/CheckSpecVersion.d.ts +0 -9
  130. package/extrinsic/extensions/known/CheckSpecVersion.js +0 -15
  131. package/extrinsic/extensions/known/CheckTxVersion.d.ts +0 -9
  132. package/extrinsic/extensions/known/CheckTxVersion.js +0 -15
  133. package/extrinsic/extensions/known/CheckWeight.d.ts +0 -6
  134. package/extrinsic/extensions/known/CheckWeight.js +0 -6
  135. package/extrinsic/extensions/known/PrevalidateAttests.d.ts +0 -7
  136. package/extrinsic/extensions/known/PrevalidateAttests.js +0 -7
  137. package/extrinsic/extensions/known/index.d.ts +0 -3
  138. package/extrinsic/extensions/known/index.js +0 -22
  139. package/extrinsic/index.d.ts +0 -2
  140. package/extrinsic/index.js +0 -2
  141. package/json-rpc/JsonRpcClient.d.ts +0 -49
  142. package/json-rpc/JsonRpcClient.js +0 -153
  143. package/json-rpc/index.d.ts +0 -1
  144. package/json-rpc/index.js +0 -1
  145. package/proxychain.d.ts +0 -14
  146. package/proxychain.js +0 -23
  147. package/storage/QueryableStorage.d.ts +0 -35
  148. package/storage/QueryableStorage.js +0 -157
  149. package/storage/index.d.ts +0 -1
  150. package/storage/index.js +0 -1
  151. package/types.d.ts +0 -103
  152. package/types.js +0 -1
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
 
@@ -18,8 +19,12 @@ _Note: The project is still in active development phase, the information on this
18
19
  - ✅ Familiar api style with `@polkadot/api`, easy & fast migration!
19
20
  - ✅ Native TypeScript type system for scale-codec
20
21
  - ✅ Compatible with `@polkadot/extension`-based wallets
21
- - ⏳ Use the new JSON-RPC APIs ([v2](https://paritytech.github.io/json-rpc-interface-spec/introduction.html))
22
22
  - ✅ Support Metadata V14, V15 (latest)
23
+ - ✅ Build on top of both the [new](https://paritytech.github.io/json-rpc-interface-spec/introduction.html) & legacy (deprecated soon) JSON-RPC APIs
24
+ - ✅ Support light clients (e.g: [smoldot](https://www.npmjs.com/package/smoldot)) (_docs coming soon_)
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)
23
28
 
24
29
  ### Have a quick taste
25
30
 
@@ -27,32 +32,33 @@ Try `dedot` now on [CodeSandbox Playground](https://codesandbox.io/p/devbox/tryd
27
32
  - Install `dedot` package
28
33
  ```shell
29
34
  # via yarn
30
- yarn add dedot
35
+ yarn add dedot@latest
31
36
 
32
37
  # via npm
33
- npm i dedot
38
+ npm i dedot@latest
34
39
  ```
35
40
 
36
41
  - Install `@dedot/chaintypes` package for chain types & APIs suggestion. Skip this step if you don't use TypeScript.
37
42
  ```shell
38
43
  # via yarn
39
- yarn add -D @dedot/chaintypes
44
+ yarn add -D @dedot/chaintypes@latest
40
45
 
41
46
  # via npm
42
- npm i -D @dedot/chaintypes
47
+ npm i -D @dedot/chaintypes@latest
43
48
  ```
44
49
 
45
50
  - Initialize the API client and start interacting with Polkadot network
46
51
  ```typescript
47
52
  // main.ts
48
- import { Dedot } from 'dedot';
53
+ import { DedotClient, WsProvider } from 'dedot';
49
54
  import type { PolkadotApi } from '@dedot/chaintypes';
50
55
 
51
56
  const run = async () => {
52
- const api = await Dedot.new<PolkadotApi>('wss://rpc.polkadot.io');
57
+ const provider = new WsProvider('wss://rpc.polkadot.io');
58
+ const api = await DedotClient.new<PolkadotApi>(provider);
53
59
 
54
60
  // Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
55
- const metadata = await api.rpc.state.getMetadata();
61
+ const metadata = await api.rpc.state_getMetadata();
56
62
  console.log('Metadata:', metadata);
57
63
 
58
64
  // Query on-chain storage
@@ -83,10 +89,20 @@ run().catch(console.error);
83
89
 
84
90
  ```js
85
91
  // main.js
86
- const { Dedot } = require('dedot');
92
+ const { DedotClient, WsProvider } = require('dedot');
87
93
  // ...
88
- const api = await Dedot.new('wss://rpc.polkadot.io');
94
+ const provider = new WsProvider('wss://rpc.polkadot.io');
95
+ const api = await DedotClient.new(provider);
89
96
  ```
97
+
98
+ - If the JSON-RPC server doesn't support [new](https://paritytech.github.io/json-rpc-interface-spec/introduction.html) JSON-RPC APIs yet, you can connect using the `LegacyClient` which build on top of the legacy JSON-RPC APIs.
99
+ ```typescript
100
+ import { LegacyClient, WsProvider } from 'dedot';
101
+
102
+ const provider = new WsProvider('wss://rpc.polkadot.io');
103
+ const api = await LegacyClient.new(provider);
104
+ ```
105
+
90
106
  ### Table of contents
91
107
  - [Status](#status)
92
108
  - [Chain Types & APIs](#chain-types--apis)
@@ -100,89 +116,67 @@ const api = await Dedot.new('wss://rpc.polkadot.io');
100
116
  - [`@polkadot/api` -> `dedot`](#migration-from-polkadotapi-to-dedot)
101
117
  - [Credit](#credit)
102
118
 
103
- ### Status
104
-
105
- | Feature | Status |
106
- |-------------------------------------------------------------|--------|
107
- | Execute RPC (`api.rpc`) | ✅ |
108
- | Query On-chain Storage (`api.query`) | ✅ |
109
- | Get runtime constants (`api.consts`) | ✅ |
110
- | Runtime APIs (`api.call`) | ✅ |
111
- | Transaction APIs (`api.tx`) | ✅ |
112
- | Events (`api.events`) | ✅ |
113
- | Errors (`api.errors`) | ✅ |
114
- | Contract APIs | ⏳ |
115
- | Metadata v14 | ✅ |
116
- | Metadata v15 | ✅ |
117
- | [RPC v2](https://github.com/dedotdev/dedot/issues/20) | ⏳ |
118
- | [Extrinsic V5](https://github.com/dedotdev/dedot/issues/55) | ⏳ |
119
-
120
119
  ### Chain Types & APIs
121
120
 
122
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.
123
122
 
124
- 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):
125
124
  ```shell
126
125
  # via yarn
127
- yarn add -D @dedot/chaintypes
126
+ yarn add -D @dedot/chaintypes@latest
128
127
 
129
128
  # via npm
130
- npm i -D @dedot/chaintypes
129
+ npm i -D @dedot/chaintypes@latest
131
130
  ```
132
131
 
133
- Initialize a `Dedot` instance using the `ChainApi` interface for a target chain to enable types & APIs suggestion/autocompletion for that particular chain:
132
+ Initialize a `DedotClient` instance using the `ChainApi` interface for a target chain to enable types & APIs suggestion/autocompletion for that particular chain:
133
+
134
134
  ```typescript
135
- import { Dedot } from 'dedot';
135
+ import { DedotClient, WsProvider } from 'dedot';
136
136
  import type { PolkadotApi, KusamaApi, MoonbeamApi, AstarApi } from '@dedot/chaintypes';
137
137
 
138
138
  // ...
139
139
 
140
- const polkadotApi = await Dedot.new<PolkadotApi>('wss://rpc.polkadot.io');
140
+ const polkadotApi = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io'));
141
141
  console.log(await polkadotApi.query.babe.authorities());
142
142
 
143
- const kusamaApi = await Dedot.new<KusamaApi>('wss://kusama-rpc.polkadot.io');
143
+ const kusamaApi = await DedotClient.new<KusamaApi>(new WsProvider('wss://kusama-rpc.polkadot.io'));
144
144
  console.log(await kusamaApi.query.society.memberCount());
145
145
 
146
- const moonbeamApi = await Dedot.new<MoonbeamApi>('wss://wss.api.moonbeam.network');
146
+ const moonbeamApi = await DedotClient.new<MoonbeamApi>(new WsProvider('wss://wss.api.moonbeam.network'));
147
147
  console.log(await moonbeamApi.query.ethereumChainId.chainId());
148
148
 
149
- const astarApi = await Dedot.new<AstarApi>('wss://rpc.astar.network');
149
+ const astarApi = await DedotClient.new<AstarApi>(new WsProvider('wss://rpc.astar.network'));
150
150
  console.log(await astarApi.query.dappsStaking.blockRewardAccumulator());
151
151
 
152
- const genericApi = await Dedot.new('ws://localhost:9944');
152
+ const genericApi = await DedotClient.new(new WsProvider('ws://localhost:9944'));
153
153
 
154
154
  // ...
155
155
  ```
156
156
 
157
- 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.
158
158
 
159
159
  ```shell
160
- # Install @dedot/cli via yarn
161
- yarn add -D @dedot/cli
162
-
163
- # Or via npm
164
- npm i -D @dedot/cli
165
-
166
160
  # Generate ChainApi interface for Polkadot network via rpc endpoint: wss://rpc.polkadot.io
167
161
  npx dedot chaintypes -w wss://rpc.polkadot.io
168
162
  ```
169
163
 
170
164
  ### Execute RPC Methods
171
165
 
172
- 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.<module>.<methodName>`. 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.
173
167
 
174
168
  Examples:
175
169
  ```typescript
176
170
  // Call rpc: `state_getMetadata`
177
- const metadata = await api.rpc.state.getMetadata();
171
+ const metadata = await api.rpc.state_getMetadata();
178
172
 
179
173
  // Call an arbitrary rpc: `module_rpc_name` with arguments ['param1', 'param2']
180
- const result = await api.rpc.module.rpc_name('param1', 'param2');
174
+ const result = await api.rpc.module_rpc_name('param1', 'param2');
181
175
  ```
182
176
 
183
177
  ### Query On-chain Storage
184
178
 
185
- 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.
186
180
 
187
181
  Examples:
188
182
  ```typescript
@@ -194,7 +188,7 @@ const events = await api.query.system.events();
194
188
  ```
195
189
  ### Constants
196
190
 
197
- 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.
198
192
 
199
193
  Examples:
200
194
  ```typescript
@@ -207,7 +201,7 @@ const existentialDeposit = api.consts.balances.existentialDeposit;
207
201
 
208
202
  ### Runtime APIs
209
203
 
210
- 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.
211
205
 
212
206
  Examples:
213
207
  ```typescript
@@ -222,28 +216,28 @@ const queryInfo = await api.call.transactionPaymentApi.queryInfo(tx.toU8a(), tx.
222
216
  const runtimeVersion = await api.call.core.version();
223
217
  ```
224
218
 
225
- For chains that only support Metadata V14, we need to bring in the Runtime Api definitions when initializing the Dedot client instance to encode & decode the calls. You can find all supported Runtime Api definitions in [`@dedot/specs`](https://github.com/dedotdev/dedot/blob/60de0fed8ba19c67a7e174c6168a127fdbf6caef/packages/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.
226
220
 
227
221
  Examples:
228
222
  ```typescript
229
- import { RuntimeApis } from '@dedot/specs';
230
- const api = await Dedot.new({ endpoint: 'wss://rpc.mynetwork.com', runtimeApis: RuntimeApis });
223
+ import { RuntimeApis } from 'dedot/runtime-specs';
224
+ const api = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: RuntimeApis });
231
225
 
232
226
  // Or bring in only the Runtime Api definition that you want to interact with
233
- import { AccountNonceApi } from '@dedot/specs';
234
- const api = await Dedot.new({ endpoint: 'wss://rpc.mynetwork.com', runtimeApis: { AccountNonceApi } });
227
+ import { AccountNonceApi } from 'dedot/runtime-specs';
228
+ const api = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: { AccountNonceApi } });
235
229
 
236
230
  // Get account nonce
237
231
  const nonce = await api.call.accountNonceApi.accountNonce(<address>);
238
232
  ```
239
233
 
240
- 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/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).
241
235
 
242
236
  ### Transaction APIs
243
237
 
244
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.
245
239
 
246
- 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.
247
241
 
248
242
  Example 1: Sign transaction with a Keying account
249
243
  ```typescript
@@ -257,8 +251,8 @@ const alice = keyring.addFromUri('//Alice');
257
251
  const unsub = await api.tx.balances
258
252
  .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
259
253
  .signAndSend(alice, async ({ status }) => {
260
- console.log('Transaction status', status.tag);
261
- if (status.tag === 'InBlock') {
254
+ console.log('Transaction status', status.type);
255
+ if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
262
256
  console.log(`Transaction completed at block hash ${status.value}`);
263
257
  await unsub();
264
258
  }
@@ -274,8 +268,8 @@ const signer = injected.signer;
274
268
  const unsub = await api.tx.balances
275
269
  .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
276
270
  .signAndSend(account.address, { signer }, async ({ status }) => {
277
- console.log('Transaction status', status.tag);
278
- if (status.tag === 'InBlock') {
271
+ console.log('Transaction status', status.type);
272
+ if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
279
273
  console.log(`Transaction completed at block hash ${status.value}`);
280
274
  await unsub();
281
275
  }
@@ -303,8 +297,8 @@ const remarkCall: PolkadotRuntimeRuntimeCallLike = {
303
297
 
304
298
  const unsub = api.tx.utility.batch([transferTx.call, remarkCall])
305
299
  .signAndSend(account.address, { signer }, async ({ status }) => {
306
- console.log('Transaction status', status.tag);
307
- if (status.tag === 'InBlock') {
300
+ console.log('Transaction status', status.type);
301
+ if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
308
302
  console.log(`Transaction completed at block hash ${status.value}`);
309
303
  await unsub();
310
304
  }
@@ -316,26 +310,26 @@ const unsub = api.tx.utility.batch([transferTx.call, remarkCall])
316
310
 
317
311
  ```typescript
318
312
  import { WestendAssetHubApi, XcmVersionedLocation, XcmVersionedAssets, XcmV3WeightLimit } from '@dedot/chaintypes/westendAssetHub';
319
- import { AccountId32 } from '@dedot/codecs';
313
+ import { AccountId32 } from 'dedot/codecs';
320
314
 
321
315
  const TWO_TOKENS = 2_000_000_000_000n;
322
316
  const destAddress = <bobAddress>;
323
317
 
324
- const api = await Dedot.new<WestendAssetHubApi>('...westend-assethub-rpc...');
318
+ const api = await DedotClient.new<WestendAssetHubApi>('...westend-assethub-rpc...');
325
319
 
326
320
  const dest: XcmVersionedLocation = {
327
- tag: 'V3',
328
- value: { parents: 1, interior: { tag: 'Here' } },
321
+ type: 'V3',
322
+ value: { parents: 1, interior: { type: 'Here' } },
329
323
  };
330
324
 
331
325
  const beneficiary: XcmVersionedLocation = {
332
- tag: 'V3',
326
+ type: 'V3',
333
327
  value: {
334
328
  parents: 0,
335
329
  interior: {
336
- tag: 'X1',
330
+ type: 'X1',
337
331
  value: {
338
- tag: 'AccountId32',
332
+ type: 'AccountId32',
339
333
  value: { id: new AccountId32(destAddress).raw },
340
334
  },
341
335
  },
@@ -343,25 +337,25 @@ const beneficiary: XcmVersionedLocation = {
343
337
  };
344
338
 
345
339
  const assets: XcmVersionedAssets = {
346
- tag: 'V3',
340
+ type: 'V3',
347
341
  value: [
348
342
  {
349
343
  id: {
350
- tag: 'Concrete',
344
+ type: 'Concrete',
351
345
  value: {
352
346
  parents: 1,
353
- interior: { tag: 'Here' },
347
+ interior: { type: 'Here' },
354
348
  },
355
349
  },
356
350
  fun: {
357
- tag: 'Fungible',
351
+ type: 'Fungible',
358
352
  value: TWO_TOKENS,
359
353
  },
360
354
  },
361
355
  ],
362
356
  };
363
357
 
364
- const weight: XcmV3WeightLimit = { tag: 'Unlimited' };
358
+ const weight: XcmV3WeightLimit = { type: 'Unlimited' };
365
359
 
366
360
  api.tx.polkadotXcm
367
361
  .limitedTeleportAssets(dest, beneficiary, assets, 0, weight)
@@ -374,7 +368,7 @@ api.tx.polkadotXcm
374
368
 
375
369
  ### Events
376
370
 
377
- 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.
378
372
 
379
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.
380
374
 
@@ -398,7 +392,7 @@ await api.query.system.events(async (eventRecords) => {
398
392
 
399
393
  ### Errors
400
394
 
401
- 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).
402
396
 
403
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.
404
398
 
@@ -409,7 +403,7 @@ await api.query.system.events(async (eventRecords) => {
409
403
  for (const tx of eventRecords) {
410
404
  if (api.events.system.ExtrinsicFailed.is(tx.event)) {
411
405
  const { dispatchError } = tx.event.palletEvent.data;
412
- if (dispatchError.tag === 'Module' && api.errors.assets.AlreadyExists.is(dispatchError.value)) {
406
+ if (api.errors.assets.AlreadyExists.is(dispatchError)) {
413
407
  console.log('Assets.AlreadyExists error occurred!');
414
408
  } else {
415
409
  console.log('Other error occurred', dispatchError);
@@ -433,21 +427,21 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
433
427
  const api = await ApiPromise.create({ provider: new WsProvider('wss://rpc.polkadot.io') });
434
428
  ```
435
429
  - `dedot`
430
+
436
431
  ```typescript
437
- import { Dedot } from 'dedot';
432
+ import { DedotClient, WsProvider } from 'dedot';
438
433
  import type { PolkadotApi } from '@dedot/chaintypes';
439
434
 
440
- const api = await Dedot.new<PolkadotApi>('wss://rpc.polkadot.io'); // or Dedot.create(...) if you prefer
435
+ const api = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io')); // or DedotClient.create(...) if you prefer
441
436
 
442
- // OR you want to have a custom provider
443
- import { WsProvider } from 'dedot'
444
- const api = await Dedot.new<PolkadotApi>({ provider: new WsProvider('wss://rpc.polkadot.io') });
437
+ // OR
438
+ const api = await DedotClient.new<PolkadotApi>({ provider: new WsProvider('wss://rpc.polkadot.io') });
445
439
  ```
446
440
 
447
441
  - Notes:
448
- - Under the hood, a `WsProvider` will be created if you initialize `Dedot` directly with an rpc endpoint.
449
442
  - `dedot` only supports provider can make subscription request (e.g: via Websocket).
450
- - 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.
451
445
 
452
446
  **Type system**
453
447
 
@@ -465,7 +459,7 @@ Unlike `@polkadot/api` where data are wrapped inside a [codec types](https://pol
465
459
  | `str` | `string` |
466
460
  | Tuple: `(A, B)`, `()` | `[A, B]`, `[]` |
467
461
  | Struct: `struct { field_1: u8, field_2: str }` | `{ field_1: number, field_2: string}` |
468
- | Enum: `enum { Variant1(u8), Variant2(bool), Variant3 }` | `{ tag: 'Variant1', value: number } \| { tag: 'Variant2', value: boolean } \| { tag: 'Variant2' }` |
462
+ | Enum: `enum { Variant1(u8), Variant2(bool), Variant3 }` | `{ type: 'Variant1', value: number } \| { type: 'Variant2', value: boolean } \| { type: 'Variant2' }` |
469
463
  | FlatEnum: `enum { Variant1, Variant2 }` | `'Variant1' \| 'Variant2'` |
470
464
 
471
465
  E.g 1:
package/bin/dedot ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('@dedot/cli').dedot();
@@ -1 +1 @@
1
- export * from './substrate/index.js';
1
+ export * from '@dedot/api/chaintypes';
@@ -1 +1 @@
1
- export * from './substrate/index.js';
1
+ export * from '@dedot/api/chaintypes';
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./substrate/index.js"), exports);
17
+ __exportStar(require("@dedot/api/chaintypes"), exports);
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./JsonRpcClient.js"), exports);
17
+ __exportStar(require("@dedot/codecs"), exports);
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./QueryableStorage.js"), exports);
17
+ __exportStar(require("@dedot/contracts"), exports);
package/cjs/index.js CHANGED
@@ -15,9 +15,6 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
- };
21
18
  var __importStar = (this && this.__importStar) || function (mod) {
22
19
  if (mod && mod.__esModule) return mod;
23
20
  var result = {};
@@ -25,17 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
22
  __setModuleDefault(result, mod);
26
23
  return result;
27
24
  };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.$ = exports.WsProvider = exports.Dedot = void 0;
30
- __exportStar(require("./storage/index.js"), exports);
31
- __exportStar(require("./extrinsic/index.js"), exports);
32
- __exportStar(require("./executor/index.js"), exports);
33
- __exportStar(require("./json-rpc/index.js"), exports);
34
- var index_js_1 = require("./client/index.js");
35
- Object.defineProperty(exports, "Dedot", { enumerable: true, get: function () { return index_js_1.Dedot; } });
36
- // Re-exports
37
- var providers_1 = require("@dedot/providers");
38
- Object.defineProperty(exports, "WsProvider", { enumerable: true, get: function () { return providers_1.WsProvider; } });
29
+ exports.$ = void 0;
39
30
  exports.$ = __importStar(require("@dedot/shape"));
40
- __exportStar(require("@dedot/codecs"), exports);
41
- __exportStar(require("@dedot/utils"), exports);
31
+ __exportStar(require("@dedot/api"), exports);
32
+ __exportStar(require("@dedot/providers"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dedot/runtime-specs"), exports);
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types.js"), exports);
17
+ __exportStar(require("@dedot/shape"), exports);
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Dedot.js"), exports);
17
+ __exportStar(require("@dedot/types"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dedot/types/json-rpc"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dedot/utils"), exports);
@@ -0,0 +1 @@
1
+ export * from '@dedot/codecs';
@@ -0,0 +1 @@
1
+ export * from '@dedot/codecs';
@@ -0,0 +1 @@
1
+ export * from '@dedot/contracts';
@@ -0,0 +1 @@
1
+ export * from '@dedot/contracts';
package/index.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- export type * from './types.js';
2
- export * from './storage/index.js';
3
- export * from './extrinsic/index.js';
4
- export * from './executor/index.js';
5
- export * from './json-rpc/index.js';
6
- export { Dedot } from './client/index.js';
7
- export { WsProvider } from '@dedot/providers';
8
1
  export * as $ from '@dedot/shape';
9
- export * from '@dedot/codecs';
10
- export * from '@dedot/utils';
2
+ export * from '@dedot/api';
3
+ export * from '@dedot/providers';
package/index.js CHANGED
@@ -1,10 +1,3 @@
1
- export * from './storage/index.js';
2
- export * from './extrinsic/index.js';
3
- export * from './executor/index.js';
4
- export * from './json-rpc/index.js';
5
- export { Dedot } from './client/index.js';
6
- // Re-exports
7
- export { WsProvider } from '@dedot/providers';
8
1
  export * as $ from '@dedot/shape';
9
- export * from '@dedot/codecs';
10
- export * from '@dedot/utils';
2
+ export * from '@dedot/api';
3
+ export * from '@dedot/providers';