dedot 0.4.1 → 0.5.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 (2) hide show
  1. package/README.md +97 -66
  2. package/package.json +11 -11
package/README.md CHANGED
@@ -2,12 +2,19 @@
2
2
 
3
3
  Delightful JavaScript/TypeScript client for [Polkadot](https://polkadot.network/) & [Substrate](https://substrate.io/)
4
4
 
5
- <p align="left">
6
- <img src="https://img.shields.io/github/license/dedotdev/dedot?style=flat-square"/>
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"/>
9
- <img src="https://img.shields.io/github/package-json/v/dedotdev/dedot?filename=packages%2Fapi%2Fpackage.json&style=flat-square"/>
10
- </p>
5
+ ![Version][ico-version]
6
+ ![Unit test][ico-unit-test]
7
+ ![E2E test][ico-e2e-test]
8
+ ![License][ico-license]
9
+ [![Chat on Telegram][ico-telegram]][link-telegram]
10
+
11
+ [ico-telegram]: https://img.shields.io/badge/Dedot-2CA5E0.svg?style=flat-square&logo=telegram&label=Telegram
12
+ [ico-unit-test]: https://img.shields.io/github/actions/workflow/status/dedotdev/dedot/run-tests.yml?label=unit%20tests&style=flat-square
13
+ [ico-e2e-test]: https://img.shields.io/github/actions/workflow/status/dedotdev/dedot/zombienet-tests.yml?label=e2e%20tests&style=flat-square
14
+ [ico-version]: https://img.shields.io/github/package-json/v/dedotdev/dedot?filename=packages%2Fapi%2Fpackage.json&style=flat-square
15
+ [ico-license]: https://img.shields.io/github/license/dedotdev/dedot?style=flat-square
16
+
17
+ [link-telegram]: https://t.me/JoinDedot
11
18
 
12
19
  ---
13
20
 
@@ -54,6 +61,7 @@ Delightful JavaScript/TypeScript client for [Polkadot](https://polkadot.network/
54
61
 
55
62
  ### Getting started
56
63
 
64
+ #### Installation & connecting to network
57
65
  Follow the below steps to install Dedot to your project.
58
66
 
59
67
  - Install `dedot` package
@@ -85,56 +93,73 @@ import type { PolkadotApi } from '@dedot/chaintypes';
85
93
 
86
94
  const run = async () => {
87
95
  const provider = new WsProvider('wss://rpc.polkadot.io');
88
- const api = await DedotClient.new<PolkadotApi>(provider);
96
+ const client = await DedotClient.new<PolkadotApi>(provider);
89
97
 
90
98
  // Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
91
- const metadata = await api.rpc.state_getMetadata();
99
+ const metadata = await client.rpc.state_getMetadata();
92
100
  console.log('Metadata:', metadata);
93
101
 
94
102
  // Query on-chain storage
95
- const balance = await api.query.system.account(<address>);
103
+ const balance = await client.query.system.account(<address>);
96
104
  console.log('Balance:', balance);
97
105
 
98
106
 
99
107
  // Subscribe to on-chain storage changes
100
- const unsub = await api.query.system.number((blockNumber) => {
108
+ const unsub = await client.query.system.number((blockNumber) => {
101
109
  console.log(`Current block number: ${blockNumber}`);
102
110
  });
103
111
 
104
112
  // Get pallet constants
105
- const ss58Prefix = api.consts.system.ss58Prefix;
113
+ const ss58Prefix = client.consts.system.ss58Prefix;
106
114
  console.log('Polkadot ss58Prefix:', ss58Prefix);
107
115
 
108
116
  // Call runtime api
109
- const pendingRewards = await api.call.nominationPoolsApi.pendingRewards(<address>)
117
+ const pendingRewards = await client.call.nominationPoolsApi.pendingRewards(<address>)
110
118
  console.log('Pending rewards:', pendingRewards);
111
119
 
112
120
  // await unsub();
113
- // await api.disconnect();
121
+ // await client.disconnect();
114
122
  }
115
123
 
116
124
  run().catch(console.error);
117
125
  ```
118
126
 
119
- - You can also import `dedot` using `require`.
127
+ #### Support CommonJS (`require`)
128
+
129
+ You can also import `dedot` using `require`.
120
130
 
121
131
  ```js
122
132
  // main.js
123
133
  const { DedotClient, WsProvider } = require('dedot');
124
134
  // ...
125
135
  const provider = new WsProvider('wss://rpc.polkadot.io');
126
- const api = await DedotClient.new(provider);
136
+ const client = await DedotClient.new(provider);
127
137
  ```
128
138
 
129
- - 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.
139
+ #### Using `LegacyClient` to connect via legacy JSON-RPC APIs
140
+
141
+ If the JSON-RPC server doesn't support [new JSON-RPC APIs](https://paritytech.github.io/json-rpc-interface-spec/introduction.html) yet, you can connect to the network using the `LegacyClient` which build on top of the [legacy JSON-RPC APIs](https://github.com/w3f/PSPs/blob/master/PSPs/drafts/psp-6.md).
130
142
 
131
143
  ```typescript
132
144
  import { LegacyClient, WsProvider } from 'dedot';
133
145
 
134
146
  const provider = new WsProvider('wss://rpc.polkadot.io');
135
- const api = await LegacyClient.new(provider);
147
+ const client = await LegacyClient.new(provider);
136
148
  ```
137
149
 
150
+ > [!NOTE]
151
+ > The [new JSON-RPC APIs](https://paritytech.github.io/json-rpc-interface-spec/introduction.html) are not well implemented/unstable for RPC Nodes using Polkadot-SDK version < `1.11.0`, so one should connect to the network using `LegacyClient` in such cases. For nodes using Polkadot-SDK version >= `1.11.0`, it's recommended to use `DedotClient` to connect to the network.
152
+ >
153
+ > You can easily check the current node's implementation version by calling RPC `system_version`:
154
+ > ```typescript
155
+ > const version = await client.rpc.system_version();
156
+ > ```
157
+
158
+
159
+ > [!NOTE]
160
+ > It's recommended to use `DedotClient` for better performance when you connect to the network using [smoldot](https://www.npmjs.com/package/smoldot) light client via [`SmoldotProvider`](https://github.com/dedotdev/dedot/blob/main/packages/providers/src/smoldot/SmoldotProvider.ts).
161
+
162
+
138
163
  ### Chain Types & APIs
139
164
 
140
165
  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.
@@ -157,19 +182,19 @@ import type { PolkadotApi, KusamaApi, MoonbeamApi, AstarApi } from '@dedot/chain
157
182
 
158
183
  // ...
159
184
 
160
- const polkadotApi = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io'));
161
- console.log(await polkadotApi.query.babe.authorities());
185
+ const polkadotClient = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io'));
186
+ console.log(await polkadotClient.query.babe.authorities());
162
187
 
163
- const kusamaApi = await DedotClient.new<KusamaApi>(new WsProvider('wss://kusama-rpc.polkadot.io'));
164
- console.log(await kusamaApi.query.society.memberCount());
188
+ const kusamaClient = await DedotClient.new<KusamaApi>(new WsProvider('wss://kusama-rpc.polkadot.io'));
189
+ console.log(await kusamaClient.query.society.memberCount());
165
190
 
166
- const moonbeamApi = await DedotClient.new<MoonbeamApi>(new WsProvider('wss://wss.api.moonbeam.network'));
167
- console.log(await moonbeamApi.query.ethereumChainId.chainId());
191
+ const moonbeamClient = await DedotClient.new<MoonbeamApi>(new WsProvider('wss://wss.api.moonbeam.network'));
192
+ console.log(await moonbeamClient.query.ethereumChainId.chainId());
168
193
 
169
- const astarApi = await DedotClient.new<AstarApi>(new WsProvider('wss://rpc.astar.network'));
170
- console.log(await astarApi.query.dappsStaking.blockRewardAccumulator());
194
+ const astarClient = await DedotClient.new<AstarApi>(new WsProvider('wss://rpc.astar.network'));
195
+ console.log(await astarClient.query.dappsStaking.blockRewardAccumulator());
171
196
 
172
- const genericApi = await DedotClient.new(new WsProvider('ws://localhost:9944'));
197
+ const client = await DedotClient.new(new WsProvider('ws://localhost:9944'));
173
198
 
174
199
  // ...
175
200
  ```
@@ -183,16 +208,16 @@ npx dedot chaintypes -w wss://rpc.polkadot.io
183
208
 
184
209
  ### Execute JSON-RPC Methods
185
210
 
186
- RPCs can be executed via `api.rpc` entry point. After creating a `DedotClient` 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.
211
+ RPCs can be executed via `client.rpc` entry point. After creating a `DedotClient` 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: `client.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.
187
212
 
188
213
  Examples:
189
214
 
190
215
  ```typescript
191
216
  // Call rpc: `state_getMetadata`
192
- const metadata = await api.rpc.state_getMetadata();
217
+ const metadata = await client.rpc.state_getMetadata();
193
218
 
194
219
  // Call an arbitrary rpc: `module_rpc_name` with arguments ['param1', 'param2']
195
- const result = await api.rpc.module_rpc_name('param1', 'param2');
220
+ const result = await client.rpc.module_rpc_name('param1', 'param2');
196
221
  ```
197
222
 
198
223
  For advanced users who want to interact directly with server/node via raw JSON-RPC APIs, you can use a light-weight `JsonRpcClient` for this purpose without having to use `DedotClient` or `LegacyClient`.
@@ -210,48 +235,48 @@ const chain = await client.rpc.system_chain();
210
235
 
211
236
  ### Query On-chain Storage
212
237
 
213
- 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.
238
+ On-chain storage can be queried via `client.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: `client.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.
214
239
 
215
240
  Examples:
216
241
 
217
242
  ```typescript
218
243
  // Query account balance
219
- const balance = await api.query.system.account(<address>);
244
+ const balance = await client.query.system.account(<address>);
220
245
 
221
246
  // Get all events of current block
222
- const events = await api.query.system.events();
247
+ const events = await client.query.system.events();
223
248
  ```
224
249
 
225
250
  ### Constants
226
251
 
227
- 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.
252
+ Runtime constants (parameter types) are defined in metadata, and can be inspected via `client.consts` entry point with format: `client.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.
228
253
 
229
254
  Examples:
230
255
 
231
256
  ```typescript
232
257
  // Get runtime version
233
- const runtimeVersion = api.consts.system.version;
258
+ const runtimeVersion = client.consts.system.version;
234
259
 
235
260
  // Get existential deposit in pallet balances
236
- const existentialDeposit = api.consts.balances.existentialDeposit;
261
+ const existentialDeposit = client.consts.balances.existentialDeposit;
237
262
  ```
238
263
 
239
264
  ### Runtime APIs
240
265
 
241
- 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.
266
+ 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 `client.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.
242
267
 
243
268
  Examples:
244
269
 
245
270
  ```typescript
246
271
  // Get account nonce
247
- const nonce = await api.call.accountNonceApi.accountNonce(<address>);
272
+ const nonce = await client.call.accountNonceApi.accountNonce(<address>);
248
273
 
249
274
  // Query transaction payment info
250
- const tx = api.tx.balances.transferKeepAlive(<address>, 2_000_000_000_000n);
251
- const queryInfo = await api.call.transactionPaymentApi.queryInfo(tx.toU8a(), tx.length);
275
+ const tx = client.tx.balances.transferKeepAlive(<address>, 2_000_000_000_000n);
276
+ const queryInfo = await client.call.transactionPaymentApi.queryInfo(tx.toU8a(), tx.length);
252
277
 
253
278
  // Get runtime version
254
- const runtimeVersion = await api.call.core.version();
279
+ const runtimeVersion = await client.call.core.version();
255
280
  ```
256
281
 
257
282
  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.
@@ -261,14 +286,14 @@ Examples:
261
286
  ```typescript
262
287
  import { RuntimeApis } from 'dedot/runtime-specs';
263
288
 
264
- const api = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: RuntimeApis });
289
+ const client = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: RuntimeApis });
265
290
 
266
291
  // Or bring in only the Runtime Api definition that you want to interact with
267
292
  import { AccountNonceApi } from 'dedot/runtime-specs';
268
- const api = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: { AccountNonceApi } });
293
+ const client = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: { AccountNonceApi } });
269
294
 
270
295
  // Get account nonce
271
- const nonce = await api.call.accountNonceApi.accountNonce(<address>);
296
+ const nonce = await client.call.accountNonceApi.accountNonce(<address>);
272
297
  ```
273
298
 
274
299
  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).
@@ -291,7 +316,7 @@ await cryptoWaitReady();
291
316
  const keyring = new Keyring({ type: 'sr25519' });
292
317
  const alice = keyring.addFromUri('//Alice');
293
318
 
294
- const unsub = await api.tx.balances
319
+ const unsub = await client.tx.balances
295
320
  .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
296
321
  .signAndSend(alice, async ({ status }) => {
297
322
  console.log('Transaction status', status.type);
@@ -309,7 +334,7 @@ const injected = await window.injectedWeb3['polkadot-js'].enable('A cool dapp');
309
334
  const account = (await injected.accounts.get())[0];
310
335
  const signer = injected.signer;
311
336
 
312
- const unsub = await api.tx.balances
337
+ const unsub = await client.tx.balances
313
338
  .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
314
339
  .signAndSend(account.address, { signer }, async ({ status }) => {
315
340
  console.log('Transaction status', status.type);
@@ -329,7 +354,7 @@ import type { PolkadotRuntimeRuntimeCallLike } from '@dedot/chaintypes/polkadot'
329
354
  const account = ...;
330
355
  const signer = ...;
331
356
 
332
- const transferTx = api.tx.balances.transferKeepAlive(<destAddress>, 2_000_000_000_000n);
357
+ const transferTx = client.tx.balances.transferKeepAlive(<destAddress>, 2_000_000_000_000n);
333
358
  const remarkCall: PolkadotRuntimeRuntimeCallLike = {
334
359
  pallet: 'System',
335
360
  palletCall: {
@@ -340,7 +365,7 @@ const remarkCall: PolkadotRuntimeRuntimeCallLike = {
340
365
  },
341
366
  };
342
367
 
343
- const unsub = api.tx.utility.batch([transferTx.call, remarkCall])
368
+ const unsub = client.tx.utility.batch([transferTx.call, remarkCall])
344
369
  .signAndSend(account.address, { signer }, async ({ status }) => {
345
370
  console.log('Transaction status', status.type);
346
371
  if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
@@ -360,7 +385,7 @@ import { AccountId32 } from 'dedot/codecs';
360
385
  const TWO_TOKENS = 2_000_000_000_000n;
361
386
  const destAddress = <bobAddress>;
362
387
 
363
- const api = await DedotClient.new<WestendAssetHubApi>('...westend-assethub-rpc...');
388
+ const client = await DedotClient.new<WestendAssetHubApi>('...westend-assethub-rpc...');
364
389
 
365
390
  const dest: XcmVersionedLocation = {
366
391
  type: 'V3',
@@ -402,7 +427,7 @@ const assets: XcmVersionedAssets = {
402
427
 
403
428
  const weight: XcmV3WeightLimit = { type: 'Unlimited' };
404
429
 
405
- api.tx.polkadotXcm
430
+ client.tx.polkadotXcm
406
431
  .limitedTeleportAssets(dest, beneficiary, assets, 0, weight)
407
432
  .signAndSend(alice, { signer, tip: 1_000_000n }, (result) => {
408
433
  console.dir(result, { depth: null });
@@ -413,19 +438,19 @@ api.tx.polkadotXcm
413
438
 
414
439
  ### Events
415
440
 
416
- 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.
441
+ 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 `client.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.
417
442
 
418
- 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.
443
+ This `client.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.
419
444
 
420
445
  Example to list new accounts created in each block:
421
446
 
422
447
  ```typescript
423
448
  // ...
424
- const ss58Prefix = api.consts.system.ss58Prefix;
425
- await api.query.system.events(async (eventRecords) => {
426
- const newAccountEvents = api.events.system.NewAccount.filter(eventRecords);
449
+ const ss58Prefix = client.consts.system.ss58Prefix;
450
+ await client.query.system.events(async (eventRecords) => {
451
+ const newAccountEvents = client.events.system.NewAccount.filter(eventRecords);
427
452
 
428
- console.log(newAccountEvents.length, 'account(s) was created in block', await api.query.system.number());
453
+ console.log(newAccountEvents.length, 'account(s) was created in block', await client.query.system.number());
429
454
 
430
455
  newAccountEvents.forEach((event, index) => {
431
456
  console.log(`New Account ${index + 1}:`, event.palletEvent.data.account.address(ss58Prefix));
@@ -436,7 +461,7 @@ await api.query.system.events(async (eventRecords) => {
436
461
 
437
462
  ### Errors
438
463
 
439
- 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).
464
+ 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: `client.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).
440
465
 
441
466
  Similar to events API, this API is helpful when we want to check if an error maches with an error that we're expecting.
442
467
 
@@ -444,11 +469,11 @@ Example if an error is `AlreadyExists` from `Assets` pallet:
444
469
 
445
470
  ```typescript
446
471
  // ...
447
- await api.query.system.events(async (eventRecords) => {
472
+ await client.query.system.events(async (eventRecords) => {
448
473
  for (const tx of eventRecords) {
449
- if (api.events.system.ExtrinsicFailed.is(tx.event)) {
474
+ if (client.events.system.ExtrinsicFailed.is(tx.event)) {
450
475
  const { dispatchError } = tx.event.palletEvent.data;
451
- if (api.errors.assets.AlreadyExists.is(dispatchError)) {
476
+ if (client.errors.assets.AlreadyExists.is(dispatchError)) {
452
477
  console.log('Assets.AlreadyExists error occurred!');
453
478
  } else {
454
479
  console.log('Other error occurred', dispatchError);
@@ -474,6 +499,11 @@ dedot typink -m ./path/to/metadata.json -o ./where/to-put/generated-types
474
499
  After running the command, Types & APIs of the contract will be generated.
475
500
  E.g: if the contract's name is `flipper`, the Types & APIs will be put in a folder named `flipper`, the entry-point interface for the contract will be `FlipperContractApi` in `flipper/index.d.ts` file. An example of Types & APIs for flipper contract can be found [here](https://github.com/dedotdev/dedot/tree/main/zombienet-tests/src/contracts/flipper).
476
501
 
502
+ > [!NOTE]
503
+ > If you're connecting to a local [`substrate-contracts-node`](https://github.com/paritytech/substrate-contracts-node/releases) for development, you might want to connect to the network using `LegacyClient` since the latest version of `substrate-contracts-node` ([`v0.41.0`](https://github.com/paritytech/substrate-contracts-node/releases/tag/v0.41.0)) does not working fine/comply with the latest updates for [new JSON-RPC specs](https://paritytech.github.io/json-rpc-interface-spec/introduction.html) for `DedotClient` to work properly.
504
+ >
505
+ > Following [this instruction](#using-legacyclient-to-connect-via-legacy-json-rpc-apis) to connect to the network via `LegacyClient`.
506
+
477
507
  #### Deploy contracts
478
508
 
479
509
  Whether it's to deploy a contract from a wasm code or using an existing wasm code hash. You can do it using the `ContractDeployer`.
@@ -709,7 +739,7 @@ While the api style are similar, but there're also some differences you might ne
709
739
  ```typescript
710
740
  import { ApiPromise, WsProvider } from '@polkadot/api';
711
741
 
712
- const api = await ApiPromise.create({ provider: new WsProvider('wss://rpc.polkadot.io') });
742
+ const client = await ApiPromise.create({ provider: new WsProvider('wss://rpc.polkadot.io') });
713
743
  ```
714
744
 
715
745
  - `dedot`
@@ -718,10 +748,10 @@ const api = await ApiPromise.create({ provider: new WsProvider('wss://rpc.polkad
718
748
  import { DedotClient, WsProvider } from 'dedot';
719
749
  import type { PolkadotApi } from '@dedot/chaintypes';
720
750
 
721
- const api = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io')); // or DedotClient.create(...) if you prefer
751
+ const client = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io')); // or DedotClient.create(...) if you prefer
722
752
 
723
753
  // OR
724
- const api = await DedotClient.new<PolkadotApi>({ provider: new WsProvider('wss://rpc.polkadot.io') });
754
+ const client = await DedotClient.new<PolkadotApi>({ provider: new WsProvider('wss://rpc.polkadot.io') });
725
755
  ```
726
756
 
727
757
  - Notes:
@@ -751,7 +781,7 @@ Unlike `@polkadot/api` where data are wrapped inside a [codec types](https://pol
751
781
  E.g 1:
752
782
 
753
783
  ```typescript
754
- const runtimeVersion = api.consts.system.version;
784
+ const runtimeVersion = client.consts.system.version;
755
785
 
756
786
  // @polkadot/api
757
787
  const specName: string = runtimeVersion.toJSON().specName; // OR runtimeVersion.specName.toString()
@@ -763,7 +793,7 @@ const specName: string = runtimeVersion.specName;
763
793
  E.g 2:
764
794
 
765
795
  ```typescript
766
- const balance = await api.query.system.account(<address>);
796
+ const balance = await client.query.system.account(<address>);
767
797
 
768
798
  // @polkadot/api
769
799
  const freeBalance: bigint = balance.data.free.toBigInt();
@@ -776,10 +806,10 @@ E.g 3:
776
806
 
777
807
  ```typescript
778
808
  // @polkadot/api
779
- const proposalBondMaximum: bigint | undefined = api.consts.treasury.proposalBondMaximum.unwrapOr(undefined)?.toBigInt();
809
+ const proposalBondMaximum: bigint | undefined = client.consts.treasury.proposalBondMaximum.unwrapOr(undefined)?.toBigInt();
780
810
 
781
811
  // dedot
782
- const proposalBondMaximum: bigint | undefined = api.consts.treasury.proposalBondMaximum;
812
+ const proposalBondMaximum: bigint | undefined = client.consts.treasury.proposalBondMaximum;
783
813
  ```
784
814
 
785
815
  ### Packages Structure
@@ -813,3 +843,4 @@ Proudly supported by Web3 Foundation Grants Program.
813
843
 
814
844
  [Apache-2.0](https://github.com/dedotdev/dedot/blob/main/LICENSE)
815
845
 
846
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dedot",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot",
@@ -21,15 +21,15 @@
21
21
  "clean": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo ./tsconfig.build.tsbuildinfo"
22
22
  },
23
23
  "dependencies": {
24
- "@dedot/api": "0.4.1",
25
- "@dedot/cli": "0.4.1",
26
- "@dedot/codecs": "0.4.1",
27
- "@dedot/contracts": "0.4.1",
28
- "@dedot/providers": "0.4.1",
29
- "@dedot/runtime-specs": "0.4.1",
30
- "@dedot/shape": "0.4.1",
31
- "@dedot/types": "0.4.1",
32
- "@dedot/utils": "0.4.1"
24
+ "@dedot/api": "0.5.0",
25
+ "@dedot/cli": "0.5.0",
26
+ "@dedot/codecs": "0.5.0",
27
+ "@dedot/contracts": "0.5.0",
28
+ "@dedot/providers": "0.5.0",
29
+ "@dedot/runtime-specs": "0.5.0",
30
+ "@dedot/shape": "0.5.0",
31
+ "@dedot/types": "0.5.0",
32
+ "@dedot/utils": "0.5.0"
33
33
  },
34
34
  "exports": {
35
35
  ".": {
@@ -92,7 +92,7 @@
92
92
  "directory": "dist"
93
93
  },
94
94
  "license": "Apache-2.0",
95
- "gitHead": "05b2a88dd2c78b17d68f0dd211e50be79e79852e",
95
+ "gitHead": "968148ade63e07644094fc033be719b320e18a18",
96
96
  "module": "./index.js",
97
97
  "types": "./index.d.ts"
98
98
  }