dedot 0.4.2-next.5d9d02c1.7 → 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.
- package/README.md +84 -61
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Delightful JavaScript/TypeScript client for [Polkadot](https://polkadot.network/
|
|
|
14
14
|
[ico-version]: https://img.shields.io/github/package-json/v/dedotdev/dedot?filename=packages%2Fapi%2Fpackage.json&style=flat-square
|
|
15
15
|
[ico-license]: https://img.shields.io/github/license/dedotdev/dedot?style=flat-square
|
|
16
16
|
|
|
17
|
-
[link-telegram]: https://t.me
|
|
17
|
+
[link-telegram]: https://t.me/JoinDedot
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -61,6 +61,7 @@ Delightful JavaScript/TypeScript client for [Polkadot](https://polkadot.network/
|
|
|
61
61
|
|
|
62
62
|
### Getting started
|
|
63
63
|
|
|
64
|
+
#### Installation & connecting to network
|
|
64
65
|
Follow the below steps to install Dedot to your project.
|
|
65
66
|
|
|
66
67
|
- Install `dedot` package
|
|
@@ -92,56 +93,73 @@ import type { PolkadotApi } from '@dedot/chaintypes';
|
|
|
92
93
|
|
|
93
94
|
const run = async () => {
|
|
94
95
|
const provider = new WsProvider('wss://rpc.polkadot.io');
|
|
95
|
-
const
|
|
96
|
+
const client = await DedotClient.new<PolkadotApi>(provider);
|
|
96
97
|
|
|
97
98
|
// Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
|
|
98
|
-
const metadata = await
|
|
99
|
+
const metadata = await client.rpc.state_getMetadata();
|
|
99
100
|
console.log('Metadata:', metadata);
|
|
100
101
|
|
|
101
102
|
// Query on-chain storage
|
|
102
|
-
const balance = await
|
|
103
|
+
const balance = await client.query.system.account(<address>);
|
|
103
104
|
console.log('Balance:', balance);
|
|
104
105
|
|
|
105
106
|
|
|
106
107
|
// Subscribe to on-chain storage changes
|
|
107
|
-
const unsub = await
|
|
108
|
+
const unsub = await client.query.system.number((blockNumber) => {
|
|
108
109
|
console.log(`Current block number: ${blockNumber}`);
|
|
109
110
|
});
|
|
110
111
|
|
|
111
112
|
// Get pallet constants
|
|
112
|
-
const ss58Prefix =
|
|
113
|
+
const ss58Prefix = client.consts.system.ss58Prefix;
|
|
113
114
|
console.log('Polkadot ss58Prefix:', ss58Prefix);
|
|
114
115
|
|
|
115
116
|
// Call runtime api
|
|
116
|
-
const pendingRewards = await
|
|
117
|
+
const pendingRewards = await client.call.nominationPoolsApi.pendingRewards(<address>)
|
|
117
118
|
console.log('Pending rewards:', pendingRewards);
|
|
118
119
|
|
|
119
120
|
// await unsub();
|
|
120
|
-
// await
|
|
121
|
+
// await client.disconnect();
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
run().catch(console.error);
|
|
124
125
|
```
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
#### Support CommonJS (`require`)
|
|
128
|
+
|
|
129
|
+
You can also import `dedot` using `require`.
|
|
127
130
|
|
|
128
131
|
```js
|
|
129
132
|
// main.js
|
|
130
133
|
const { DedotClient, WsProvider } = require('dedot');
|
|
131
134
|
// ...
|
|
132
135
|
const provider = new WsProvider('wss://rpc.polkadot.io');
|
|
133
|
-
const
|
|
136
|
+
const client = await DedotClient.new(provider);
|
|
134
137
|
```
|
|
135
138
|
|
|
136
|
-
|
|
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).
|
|
137
142
|
|
|
138
143
|
```typescript
|
|
139
144
|
import { LegacyClient, WsProvider } from 'dedot';
|
|
140
145
|
|
|
141
146
|
const provider = new WsProvider('wss://rpc.polkadot.io');
|
|
142
|
-
const
|
|
147
|
+
const client = await LegacyClient.new(provider);
|
|
143
148
|
```
|
|
144
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
|
+
|
|
145
163
|
### Chain Types & APIs
|
|
146
164
|
|
|
147
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.
|
|
@@ -164,19 +182,19 @@ import type { PolkadotApi, KusamaApi, MoonbeamApi, AstarApi } from '@dedot/chain
|
|
|
164
182
|
|
|
165
183
|
// ...
|
|
166
184
|
|
|
167
|
-
const
|
|
168
|
-
console.log(await
|
|
185
|
+
const polkadotClient = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io'));
|
|
186
|
+
console.log(await polkadotClient.query.babe.authorities());
|
|
169
187
|
|
|
170
|
-
const
|
|
171
|
-
console.log(await
|
|
188
|
+
const kusamaClient = await DedotClient.new<KusamaApi>(new WsProvider('wss://kusama-rpc.polkadot.io'));
|
|
189
|
+
console.log(await kusamaClient.query.society.memberCount());
|
|
172
190
|
|
|
173
|
-
const
|
|
174
|
-
console.log(await
|
|
191
|
+
const moonbeamClient = await DedotClient.new<MoonbeamApi>(new WsProvider('wss://wss.api.moonbeam.network'));
|
|
192
|
+
console.log(await moonbeamClient.query.ethereumChainId.chainId());
|
|
175
193
|
|
|
176
|
-
const
|
|
177
|
-
console.log(await
|
|
194
|
+
const astarClient = await DedotClient.new<AstarApi>(new WsProvider('wss://rpc.astar.network'));
|
|
195
|
+
console.log(await astarClient.query.dappsStaking.blockRewardAccumulator());
|
|
178
196
|
|
|
179
|
-
const
|
|
197
|
+
const client = await DedotClient.new(new WsProvider('ws://localhost:9944'));
|
|
180
198
|
|
|
181
199
|
// ...
|
|
182
200
|
```
|
|
@@ -190,16 +208,16 @@ npx dedot chaintypes -w wss://rpc.polkadot.io
|
|
|
190
208
|
|
|
191
209
|
### Execute JSON-RPC Methods
|
|
192
210
|
|
|
193
|
-
RPCs can be executed via `
|
|
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.
|
|
194
212
|
|
|
195
213
|
Examples:
|
|
196
214
|
|
|
197
215
|
```typescript
|
|
198
216
|
// Call rpc: `state_getMetadata`
|
|
199
|
-
const metadata = await
|
|
217
|
+
const metadata = await client.rpc.state_getMetadata();
|
|
200
218
|
|
|
201
219
|
// Call an arbitrary rpc: `module_rpc_name` with arguments ['param1', 'param2']
|
|
202
|
-
const result = await
|
|
220
|
+
const result = await client.rpc.module_rpc_name('param1', 'param2');
|
|
203
221
|
```
|
|
204
222
|
|
|
205
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`.
|
|
@@ -217,48 +235,48 @@ const chain = await client.rpc.system_chain();
|
|
|
217
235
|
|
|
218
236
|
### Query On-chain Storage
|
|
219
237
|
|
|
220
|
-
On-chain storage can be queried via `
|
|
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.
|
|
221
239
|
|
|
222
240
|
Examples:
|
|
223
241
|
|
|
224
242
|
```typescript
|
|
225
243
|
// Query account balance
|
|
226
|
-
const balance = await
|
|
244
|
+
const balance = await client.query.system.account(<address>);
|
|
227
245
|
|
|
228
246
|
// Get all events of current block
|
|
229
|
-
const events = await
|
|
247
|
+
const events = await client.query.system.events();
|
|
230
248
|
```
|
|
231
249
|
|
|
232
250
|
### Constants
|
|
233
251
|
|
|
234
|
-
Runtime constants (parameter types) are defined in metadata, and can be inspected via `
|
|
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.
|
|
235
253
|
|
|
236
254
|
Examples:
|
|
237
255
|
|
|
238
256
|
```typescript
|
|
239
257
|
// Get runtime version
|
|
240
|
-
const runtimeVersion =
|
|
258
|
+
const runtimeVersion = client.consts.system.version;
|
|
241
259
|
|
|
242
260
|
// Get existential deposit in pallet balances
|
|
243
|
-
const existentialDeposit =
|
|
261
|
+
const existentialDeposit = client.consts.balances.existentialDeposit;
|
|
244
262
|
```
|
|
245
263
|
|
|
246
264
|
### Runtime APIs
|
|
247
265
|
|
|
248
|
-
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 `
|
|
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.
|
|
249
267
|
|
|
250
268
|
Examples:
|
|
251
269
|
|
|
252
270
|
```typescript
|
|
253
271
|
// Get account nonce
|
|
254
|
-
const nonce = await
|
|
272
|
+
const nonce = await client.call.accountNonceApi.accountNonce(<address>);
|
|
255
273
|
|
|
256
274
|
// Query transaction payment info
|
|
257
|
-
const tx =
|
|
258
|
-
const queryInfo = await
|
|
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);
|
|
259
277
|
|
|
260
278
|
// Get runtime version
|
|
261
|
-
const runtimeVersion = await
|
|
279
|
+
const runtimeVersion = await client.call.core.version();
|
|
262
280
|
```
|
|
263
281
|
|
|
264
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.
|
|
@@ -268,14 +286,14 @@ Examples:
|
|
|
268
286
|
```typescript
|
|
269
287
|
import { RuntimeApis } from 'dedot/runtime-specs';
|
|
270
288
|
|
|
271
|
-
const
|
|
289
|
+
const client = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: RuntimeApis });
|
|
272
290
|
|
|
273
291
|
// Or bring in only the Runtime Api definition that you want to interact with
|
|
274
292
|
import { AccountNonceApi } from 'dedot/runtime-specs';
|
|
275
|
-
const
|
|
293
|
+
const client = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: { AccountNonceApi } });
|
|
276
294
|
|
|
277
295
|
// Get account nonce
|
|
278
|
-
const nonce = await
|
|
296
|
+
const nonce = await client.call.accountNonceApi.accountNonce(<address>);
|
|
279
297
|
```
|
|
280
298
|
|
|
281
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).
|
|
@@ -298,7 +316,7 @@ await cryptoWaitReady();
|
|
|
298
316
|
const keyring = new Keyring({ type: 'sr25519' });
|
|
299
317
|
const alice = keyring.addFromUri('//Alice');
|
|
300
318
|
|
|
301
|
-
const unsub = await
|
|
319
|
+
const unsub = await client.tx.balances
|
|
302
320
|
.transferKeepAlive(<destAddress>, 2_000_000_000_000n)
|
|
303
321
|
.signAndSend(alice, async ({ status }) => {
|
|
304
322
|
console.log('Transaction status', status.type);
|
|
@@ -316,7 +334,7 @@ const injected = await window.injectedWeb3['polkadot-js'].enable('A cool dapp');
|
|
|
316
334
|
const account = (await injected.accounts.get())[0];
|
|
317
335
|
const signer = injected.signer;
|
|
318
336
|
|
|
319
|
-
const unsub = await
|
|
337
|
+
const unsub = await client.tx.balances
|
|
320
338
|
.transferKeepAlive(<destAddress>, 2_000_000_000_000n)
|
|
321
339
|
.signAndSend(account.address, { signer }, async ({ status }) => {
|
|
322
340
|
console.log('Transaction status', status.type);
|
|
@@ -336,7 +354,7 @@ import type { PolkadotRuntimeRuntimeCallLike } from '@dedot/chaintypes/polkadot'
|
|
|
336
354
|
const account = ...;
|
|
337
355
|
const signer = ...;
|
|
338
356
|
|
|
339
|
-
const transferTx =
|
|
357
|
+
const transferTx = client.tx.balances.transferKeepAlive(<destAddress>, 2_000_000_000_000n);
|
|
340
358
|
const remarkCall: PolkadotRuntimeRuntimeCallLike = {
|
|
341
359
|
pallet: 'System',
|
|
342
360
|
palletCall: {
|
|
@@ -347,7 +365,7 @@ const remarkCall: PolkadotRuntimeRuntimeCallLike = {
|
|
|
347
365
|
},
|
|
348
366
|
};
|
|
349
367
|
|
|
350
|
-
const unsub =
|
|
368
|
+
const unsub = client.tx.utility.batch([transferTx.call, remarkCall])
|
|
351
369
|
.signAndSend(account.address, { signer }, async ({ status }) => {
|
|
352
370
|
console.log('Transaction status', status.type);
|
|
353
371
|
if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
|
|
@@ -367,7 +385,7 @@ import { AccountId32 } from 'dedot/codecs';
|
|
|
367
385
|
const TWO_TOKENS = 2_000_000_000_000n;
|
|
368
386
|
const destAddress = <bobAddress>;
|
|
369
387
|
|
|
370
|
-
const
|
|
388
|
+
const client = await DedotClient.new<WestendAssetHubApi>('...westend-assethub-rpc...');
|
|
371
389
|
|
|
372
390
|
const dest: XcmVersionedLocation = {
|
|
373
391
|
type: 'V3',
|
|
@@ -409,7 +427,7 @@ const assets: XcmVersionedAssets = {
|
|
|
409
427
|
|
|
410
428
|
const weight: XcmV3WeightLimit = { type: 'Unlimited' };
|
|
411
429
|
|
|
412
|
-
|
|
430
|
+
client.tx.polkadotXcm
|
|
413
431
|
.limitedTeleportAssets(dest, beneficiary, assets, 0, weight)
|
|
414
432
|
.signAndSend(alice, { signer, tip: 1_000_000n }, (result) => {
|
|
415
433
|
console.dir(result, { depth: null });
|
|
@@ -420,19 +438,19 @@ api.tx.polkadotXcm
|
|
|
420
438
|
|
|
421
439
|
### Events
|
|
422
440
|
|
|
423
|
-
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 `
|
|
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.
|
|
424
442
|
|
|
425
|
-
This `
|
|
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.
|
|
426
444
|
|
|
427
445
|
Example to list new accounts created in each block:
|
|
428
446
|
|
|
429
447
|
```typescript
|
|
430
448
|
// ...
|
|
431
|
-
const ss58Prefix =
|
|
432
|
-
await
|
|
433
|
-
const newAccountEvents =
|
|
449
|
+
const ss58Prefix = client.consts.system.ss58Prefix;
|
|
450
|
+
await client.query.system.events(async (eventRecords) => {
|
|
451
|
+
const newAccountEvents = client.events.system.NewAccount.filter(eventRecords);
|
|
434
452
|
|
|
435
|
-
console.log(newAccountEvents.length, 'account(s) was created in block', await
|
|
453
|
+
console.log(newAccountEvents.length, 'account(s) was created in block', await client.query.system.number());
|
|
436
454
|
|
|
437
455
|
newAccountEvents.forEach((event, index) => {
|
|
438
456
|
console.log(`New Account ${index + 1}:`, event.palletEvent.data.account.address(ss58Prefix));
|
|
@@ -443,7 +461,7 @@ await api.query.system.events(async (eventRecords) => {
|
|
|
443
461
|
|
|
444
462
|
### Errors
|
|
445
463
|
|
|
446
|
-
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: `
|
|
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).
|
|
447
465
|
|
|
448
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.
|
|
449
467
|
|
|
@@ -451,11 +469,11 @@ Example if an error is `AlreadyExists` from `Assets` pallet:
|
|
|
451
469
|
|
|
452
470
|
```typescript
|
|
453
471
|
// ...
|
|
454
|
-
await
|
|
472
|
+
await client.query.system.events(async (eventRecords) => {
|
|
455
473
|
for (const tx of eventRecords) {
|
|
456
|
-
if (
|
|
474
|
+
if (client.events.system.ExtrinsicFailed.is(tx.event)) {
|
|
457
475
|
const { dispatchError } = tx.event.palletEvent.data;
|
|
458
|
-
if (
|
|
476
|
+
if (client.errors.assets.AlreadyExists.is(dispatchError)) {
|
|
459
477
|
console.log('Assets.AlreadyExists error occurred!');
|
|
460
478
|
} else {
|
|
461
479
|
console.log('Other error occurred', dispatchError);
|
|
@@ -481,6 +499,11 @@ dedot typink -m ./path/to/metadata.json -o ./where/to-put/generated-types
|
|
|
481
499
|
After running the command, Types & APIs of the contract will be generated.
|
|
482
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).
|
|
483
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
|
+
|
|
484
507
|
#### Deploy contracts
|
|
485
508
|
|
|
486
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`.
|
|
@@ -716,7 +739,7 @@ While the api style are similar, but there're also some differences you might ne
|
|
|
716
739
|
```typescript
|
|
717
740
|
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
718
741
|
|
|
719
|
-
const
|
|
742
|
+
const client = await ApiPromise.create({ provider: new WsProvider('wss://rpc.polkadot.io') });
|
|
720
743
|
```
|
|
721
744
|
|
|
722
745
|
- `dedot`
|
|
@@ -725,10 +748,10 @@ const api = await ApiPromise.create({ provider: new WsProvider('wss://rpc.polkad
|
|
|
725
748
|
import { DedotClient, WsProvider } from 'dedot';
|
|
726
749
|
import type { PolkadotApi } from '@dedot/chaintypes';
|
|
727
750
|
|
|
728
|
-
const
|
|
751
|
+
const client = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io')); // or DedotClient.create(...) if you prefer
|
|
729
752
|
|
|
730
753
|
// OR
|
|
731
|
-
const
|
|
754
|
+
const client = await DedotClient.new<PolkadotApi>({ provider: new WsProvider('wss://rpc.polkadot.io') });
|
|
732
755
|
```
|
|
733
756
|
|
|
734
757
|
- Notes:
|
|
@@ -758,7 +781,7 @@ Unlike `@polkadot/api` where data are wrapped inside a [codec types](https://pol
|
|
|
758
781
|
E.g 1:
|
|
759
782
|
|
|
760
783
|
```typescript
|
|
761
|
-
const runtimeVersion =
|
|
784
|
+
const runtimeVersion = client.consts.system.version;
|
|
762
785
|
|
|
763
786
|
// @polkadot/api
|
|
764
787
|
const specName: string = runtimeVersion.toJSON().specName; // OR runtimeVersion.specName.toString()
|
|
@@ -770,7 +793,7 @@ const specName: string = runtimeVersion.specName;
|
|
|
770
793
|
E.g 2:
|
|
771
794
|
|
|
772
795
|
```typescript
|
|
773
|
-
const balance = await
|
|
796
|
+
const balance = await client.query.system.account(<address>);
|
|
774
797
|
|
|
775
798
|
// @polkadot/api
|
|
776
799
|
const freeBalance: bigint = balance.data.free.toBigInt();
|
|
@@ -783,10 +806,10 @@ E.g 3:
|
|
|
783
806
|
|
|
784
807
|
```typescript
|
|
785
808
|
// @polkadot/api
|
|
786
|
-
const proposalBondMaximum: bigint | undefined =
|
|
809
|
+
const proposalBondMaximum: bigint | undefined = client.consts.treasury.proposalBondMaximum.unwrapOr(undefined)?.toBigInt();
|
|
787
810
|
|
|
788
811
|
// dedot
|
|
789
|
-
const proposalBondMaximum: bigint | undefined =
|
|
812
|
+
const proposalBondMaximum: bigint | undefined = client.consts.treasury.proposalBondMaximum;
|
|
790
813
|
```
|
|
791
814
|
|
|
792
815
|
### Packages Structure
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dedot",
|
|
3
|
-
"version": "0.
|
|
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.
|
|
25
|
-
"@dedot/cli": "0.
|
|
26
|
-
"@dedot/codecs": "0.
|
|
27
|
-
"@dedot/contracts": "0.
|
|
28
|
-
"@dedot/providers": "0.
|
|
29
|
-
"@dedot/runtime-specs": "0.
|
|
30
|
-
"@dedot/shape": "0.
|
|
31
|
-
"@dedot/types": "0.
|
|
32
|
-
"@dedot/utils": "0.
|
|
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": "
|
|
95
|
+
"gitHead": "968148ade63e07644094fc033be719b320e18a18",
|
|
96
96
|
"module": "./index.js",
|
|
97
97
|
"types": "./index.d.ts"
|
|
98
98
|
}
|