dedot 0.0.1-alpha.33 → 0.0.1-alpha.35
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 +51 -40
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -19,9 +19,9 @@ _Note: The project is still in active development phase, the information on this
|
|
|
19
19
|
- ✅ Native TypeScript type system for scale-codec
|
|
20
20
|
- ✅ Compatible with `@polkadot/extension`-based wallets
|
|
21
21
|
- ✅ Support Metadata V14, V15 (latest)
|
|
22
|
-
- ✅
|
|
23
|
-
- ✅ Support light clients (e.g: [smoldot](https://www.npmjs.com/package/smoldot))
|
|
24
|
-
-
|
|
22
|
+
- ✅ Build on top of both the [new](https://paritytech.github.io/json-rpc-interface-spec/introduction.html) & legacy (deprecated soon) JSON-RPC APIs
|
|
23
|
+
- ✅ Support light clients (e.g: [smoldot](https://www.npmjs.com/package/smoldot)) (_docs coming soon_)
|
|
24
|
+
- ✅ Typed Contract APIs (_docs coming soon_)
|
|
25
25
|
|
|
26
26
|
### Have a quick taste
|
|
27
27
|
|
|
@@ -47,12 +47,12 @@ npm i -D @dedot/chaintypes
|
|
|
47
47
|
- Initialize the API client and start interacting with Polkadot network
|
|
48
48
|
```typescript
|
|
49
49
|
// main.ts
|
|
50
|
-
import {
|
|
50
|
+
import { DedotClient, WsProvider } from 'dedot';
|
|
51
51
|
import type { PolkadotApi } from '@dedot/chaintypes';
|
|
52
52
|
|
|
53
53
|
const run = async () => {
|
|
54
54
|
const provider = new WsProvider('wss://rpc.polkadot.io');
|
|
55
|
-
const api = await
|
|
55
|
+
const api = await DedotClient.new<PolkadotApi>(provider);
|
|
56
56
|
|
|
57
57
|
// Call rpc `state_getMetadata` to fetch raw scale-encoded metadata and decode it.
|
|
58
58
|
const metadata = await api.rpc.state_getMetadata();
|
|
@@ -86,11 +86,20 @@ run().catch(console.error);
|
|
|
86
86
|
|
|
87
87
|
```js
|
|
88
88
|
// main.js
|
|
89
|
-
const {
|
|
89
|
+
const { DedotClient, WsProvider } = require('dedot');
|
|
90
90
|
// ...
|
|
91
91
|
const provider = new WsProvider('wss://rpc.polkadot.io');
|
|
92
|
-
const api = await
|
|
92
|
+
const api = await DedotClient.new(provider);
|
|
93
93
|
```
|
|
94
|
+
|
|
95
|
+
- 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.
|
|
96
|
+
```typescript
|
|
97
|
+
import { LegacyClient, WsProvider } from 'dedot';
|
|
98
|
+
|
|
99
|
+
const provider = new WsProvider('wss://rpc.polkadot.io');
|
|
100
|
+
const api = await LegacyClient.new(provider);
|
|
101
|
+
```
|
|
102
|
+
|
|
94
103
|
### Table of contents
|
|
95
104
|
- [Status](#status)
|
|
96
105
|
- [Chain Types & APIs](#chain-types--apis)
|
|
@@ -115,7 +124,7 @@ const api = await Dedot.new(provider);
|
|
|
115
124
|
| Transaction APIs (`api.tx`) | ✅ |
|
|
116
125
|
| Events (`api.events`) | ✅ |
|
|
117
126
|
| Errors (`api.errors`) | ✅ |
|
|
118
|
-
| Contract APIs |
|
|
127
|
+
| Contract APIs | ✅ |
|
|
119
128
|
| Metadata v14 | ✅ |
|
|
120
129
|
| Metadata v15 | ✅ |
|
|
121
130
|
| [RPC v2](https://github.com/dedotdev/dedot/issues/20) | ✅ |
|
|
@@ -134,26 +143,27 @@ yarn add -D @dedot/chaintypes
|
|
|
134
143
|
npm i -D @dedot/chaintypes
|
|
135
144
|
```
|
|
136
145
|
|
|
137
|
-
Initialize a `
|
|
146
|
+
Initialize a `DedotClient` instance using the `ChainApi` interface for a target chain to enable types & APIs suggestion/autocompletion for that particular chain:
|
|
147
|
+
|
|
138
148
|
```typescript
|
|
139
|
-
import {
|
|
149
|
+
import { DedotClient, WsProvider } from 'dedot';
|
|
140
150
|
import type { PolkadotApi, KusamaApi, MoonbeamApi, AstarApi } from '@dedot/chaintypes';
|
|
141
151
|
|
|
142
152
|
// ...
|
|
143
153
|
|
|
144
|
-
const polkadotApi = await
|
|
154
|
+
const polkadotApi = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io'));
|
|
145
155
|
console.log(await polkadotApi.query.babe.authorities());
|
|
146
156
|
|
|
147
|
-
const kusamaApi = await
|
|
157
|
+
const kusamaApi = await DedotClient.new<KusamaApi>(new WsProvider('wss://kusama-rpc.polkadot.io'));
|
|
148
158
|
console.log(await kusamaApi.query.society.memberCount());
|
|
149
159
|
|
|
150
|
-
const moonbeamApi = await
|
|
160
|
+
const moonbeamApi = await DedotClient.new<MoonbeamApi>(new WsProvider('wss://wss.api.moonbeam.network'));
|
|
151
161
|
console.log(await moonbeamApi.query.ethereumChainId.chainId());
|
|
152
162
|
|
|
153
|
-
const astarApi = await
|
|
163
|
+
const astarApi = await DedotClient.new<AstarApi>(new WsProvider('wss://rpc.astar.network'));
|
|
154
164
|
console.log(await astarApi.query.dappsStaking.blockRewardAccumulator());
|
|
155
165
|
|
|
156
|
-
const genericApi = await
|
|
166
|
+
const genericApi = await DedotClient.new(new WsProvider('ws://localhost:9944'));
|
|
157
167
|
|
|
158
168
|
// ...
|
|
159
169
|
```
|
|
@@ -220,16 +230,16 @@ const queryInfo = await api.call.transactionPaymentApi.queryInfo(tx.toU8a(), tx.
|
|
|
220
230
|
const runtimeVersion = await api.call.core.version();
|
|
221
231
|
```
|
|
222
232
|
|
|
223
|
-
For chains that only support Metadata V14, we need to bring in the Runtime Api definitions when initializing the
|
|
233
|
+
For chains that only support Metadata V14, we need to bring in the Runtime Api definitions when initializing the DedotClient instance to encode & decode the calls. You can find all supported Runtime Api definitions in [`dedot/runtime-specs`](https://github.com/dedotdev/dedot/blob/60de0fed8ba19c67a7e174c6168a127fdbf6caef/packages/runtime-specs/src/runtime/all.ts#L21-L39) package.
|
|
224
234
|
|
|
225
235
|
Examples:
|
|
226
236
|
```typescript
|
|
227
237
|
import { RuntimeApis } from 'dedot/runtime-specs';
|
|
228
|
-
const api = await
|
|
238
|
+
const api = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: RuntimeApis });
|
|
229
239
|
|
|
230
240
|
// Or bring in only the Runtime Api definition that you want to interact with
|
|
231
241
|
import { AccountNonceApi } from 'dedot/runtime-specs';
|
|
232
|
-
const api = await
|
|
242
|
+
const api = await DedotClient.new({ provider: new WsProvider('wss://rpc.mynetwork.com'), runtimeApis: { AccountNonceApi } });
|
|
233
243
|
|
|
234
244
|
// Get account nonce
|
|
235
245
|
const nonce = await api.call.accountNonceApi.accountNonce(<address>);
|
|
@@ -255,8 +265,8 @@ const alice = keyring.addFromUri('//Alice');
|
|
|
255
265
|
const unsub = await api.tx.balances
|
|
256
266
|
.transferKeepAlive(<destAddress>, 2_000_000_000_000n)
|
|
257
267
|
.signAndSend(alice, async ({ status }) => {
|
|
258
|
-
console.log('Transaction status', status.
|
|
259
|
-
if (status.
|
|
268
|
+
console.log('Transaction status', status.type);
|
|
269
|
+
if (status.type === 'InBlock') {
|
|
260
270
|
console.log(`Transaction completed at block hash ${status.value}`);
|
|
261
271
|
await unsub();
|
|
262
272
|
}
|
|
@@ -272,8 +282,8 @@ const signer = injected.signer;
|
|
|
272
282
|
const unsub = await api.tx.balances
|
|
273
283
|
.transferKeepAlive(<destAddress>, 2_000_000_000_000n)
|
|
274
284
|
.signAndSend(account.address, { signer }, async ({ status }) => {
|
|
275
|
-
console.log('Transaction status', status.
|
|
276
|
-
if (status.
|
|
285
|
+
console.log('Transaction status', status.type);
|
|
286
|
+
if (status.type === 'InBlock') {
|
|
277
287
|
console.log(`Transaction completed at block hash ${status.value}`);
|
|
278
288
|
await unsub();
|
|
279
289
|
}
|
|
@@ -301,8 +311,8 @@ const remarkCall: PolkadotRuntimeRuntimeCallLike = {
|
|
|
301
311
|
|
|
302
312
|
const unsub = api.tx.utility.batch([transferTx.call, remarkCall])
|
|
303
313
|
.signAndSend(account.address, { signer }, async ({ status }) => {
|
|
304
|
-
console.log('Transaction status', status.
|
|
305
|
-
if (status.
|
|
314
|
+
console.log('Transaction status', status.type);
|
|
315
|
+
if (status.type === 'InBlock') {
|
|
306
316
|
console.log(`Transaction completed at block hash ${status.value}`);
|
|
307
317
|
await unsub();
|
|
308
318
|
}
|
|
@@ -319,21 +329,21 @@ import { AccountId32 } from 'dedot/codecs';
|
|
|
319
329
|
const TWO_TOKENS = 2_000_000_000_000n;
|
|
320
330
|
const destAddress = <bobAddress>;
|
|
321
331
|
|
|
322
|
-
const api = await
|
|
332
|
+
const api = await DedotClient.new<WestendAssetHubApi>('...westend-assethub-rpc...');
|
|
323
333
|
|
|
324
334
|
const dest: XcmVersionedLocation = {
|
|
325
|
-
|
|
326
|
-
value: { parents: 1, interior: {
|
|
335
|
+
type: 'V3',
|
|
336
|
+
value: { parents: 1, interior: { type: 'Here' } },
|
|
327
337
|
};
|
|
328
338
|
|
|
329
339
|
const beneficiary: XcmVersionedLocation = {
|
|
330
|
-
|
|
340
|
+
type: 'V3',
|
|
331
341
|
value: {
|
|
332
342
|
parents: 0,
|
|
333
343
|
interior: {
|
|
334
|
-
|
|
344
|
+
type: 'X1',
|
|
335
345
|
value: {
|
|
336
|
-
|
|
346
|
+
type: 'AccountId32',
|
|
337
347
|
value: { id: new AccountId32(destAddress).raw },
|
|
338
348
|
},
|
|
339
349
|
},
|
|
@@ -341,25 +351,25 @@ const beneficiary: XcmVersionedLocation = {
|
|
|
341
351
|
};
|
|
342
352
|
|
|
343
353
|
const assets: XcmVersionedAssets = {
|
|
344
|
-
|
|
354
|
+
type: 'V3',
|
|
345
355
|
value: [
|
|
346
356
|
{
|
|
347
357
|
id: {
|
|
348
|
-
|
|
358
|
+
type: 'Concrete',
|
|
349
359
|
value: {
|
|
350
360
|
parents: 1,
|
|
351
|
-
interior: {
|
|
361
|
+
interior: { type: 'Here' },
|
|
352
362
|
},
|
|
353
363
|
},
|
|
354
364
|
fun: {
|
|
355
|
-
|
|
365
|
+
type: 'Fungible',
|
|
356
366
|
value: TWO_TOKENS,
|
|
357
367
|
},
|
|
358
368
|
},
|
|
359
369
|
],
|
|
360
370
|
};
|
|
361
371
|
|
|
362
|
-
const weight: XcmV3WeightLimit = {
|
|
372
|
+
const weight: XcmV3WeightLimit = { type: 'Unlimited' };
|
|
363
373
|
|
|
364
374
|
api.tx.polkadotXcm
|
|
365
375
|
.limitedTeleportAssets(dest, beneficiary, assets, 0, weight)
|
|
@@ -407,7 +417,7 @@ await api.query.system.events(async (eventRecords) => {
|
|
|
407
417
|
for (const tx of eventRecords) {
|
|
408
418
|
if (api.events.system.ExtrinsicFailed.is(tx.event)) {
|
|
409
419
|
const { dispatchError } = tx.event.palletEvent.data;
|
|
410
|
-
if (dispatchError.
|
|
420
|
+
if (dispatchError.type === 'Module' && api.errors.assets.AlreadyExists.is(dispatchError.value)) {
|
|
411
421
|
console.log('Assets.AlreadyExists error occurred!');
|
|
412
422
|
} else {
|
|
413
423
|
console.log('Other error occurred', dispatchError);
|
|
@@ -431,14 +441,15 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
|
431
441
|
const api = await ApiPromise.create({ provider: new WsProvider('wss://rpc.polkadot.io') });
|
|
432
442
|
```
|
|
433
443
|
- `dedot`
|
|
444
|
+
|
|
434
445
|
```typescript
|
|
435
|
-
import {
|
|
446
|
+
import { DedotClient, WsProvider } from 'dedot';
|
|
436
447
|
import type { PolkadotApi } from '@dedot/chaintypes';
|
|
437
448
|
|
|
438
|
-
const api = await
|
|
449
|
+
const api = await DedotClient.new<PolkadotApi>(new WsProvider('wss://rpc.polkadot.io')); // or DedotClient.create(...) if you prefer
|
|
439
450
|
|
|
440
451
|
// OR
|
|
441
|
-
const api = await
|
|
452
|
+
const api = await DedotClient.new<PolkadotApi>({ provider: new WsProvider('wss://rpc.polkadot.io') });
|
|
442
453
|
```
|
|
443
454
|
|
|
444
455
|
- Notes:
|
|
@@ -461,7 +472,7 @@ Unlike `@polkadot/api` where data are wrapped inside a [codec types](https://pol
|
|
|
461
472
|
| `str` | `string` |
|
|
462
473
|
| Tuple: `(A, B)`, `()` | `[A, B]`, `[]` |
|
|
463
474
|
| Struct: `struct { field_1: u8, field_2: str }` | `{ field_1: number, field_2: string}` |
|
|
464
|
-
| Enum: `enum { Variant1(u8), Variant2(bool), Variant3 }` | `{
|
|
475
|
+
| Enum: `enum { Variant1(u8), Variant2(bool), Variant3 }` | `{ type: 'Variant1', value: number } \| { type: 'Variant2', value: boolean } \| { type: 'Variant2' }` |
|
|
465
476
|
| FlatEnum: `enum { Variant1, Variant2 }` | `'Variant1' \| 'Variant2'` |
|
|
466
477
|
|
|
467
478
|
E.g 1:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dedot",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.35",
|
|
4
4
|
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
5
|
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
6
6
|
"main": "./cjs/index.js",
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"clean": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo ./tsconfig.build.tsbuildinfo"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@dedot/api": "0.0.1-alpha.
|
|
19
|
-
"@dedot/cli": "0.0.1-alpha.
|
|
20
|
-
"@dedot/codecs": "0.0.1-alpha.
|
|
21
|
-
"@dedot/contracts": "0.0.1-alpha.
|
|
22
|
-
"@dedot/providers": "0.0.1-alpha.
|
|
23
|
-
"@dedot/runtime-specs": "0.0.1-alpha.
|
|
24
|
-
"@dedot/shape": "0.0.1-alpha.
|
|
25
|
-
"@dedot/types": "0.0.1-alpha.
|
|
26
|
-
"@dedot/utils": "0.0.1-alpha.
|
|
18
|
+
"@dedot/api": "0.0.1-alpha.35",
|
|
19
|
+
"@dedot/cli": "0.0.1-alpha.35",
|
|
20
|
+
"@dedot/codecs": "0.0.1-alpha.35",
|
|
21
|
+
"@dedot/contracts": "0.0.1-alpha.35",
|
|
22
|
+
"@dedot/providers": "0.0.1-alpha.35",
|
|
23
|
+
"@dedot/runtime-specs": "0.0.1-alpha.35",
|
|
24
|
+
"@dedot/shape": "0.0.1-alpha.35",
|
|
25
|
+
"@dedot/types": "0.0.1-alpha.35",
|
|
26
|
+
"@dedot/utils": "0.0.1-alpha.35"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"directory": "dist"
|
|
87
87
|
},
|
|
88
88
|
"license": "Apache-2.0",
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "bf954b82ac4c8a8e1d989c0c708a099269eb4262",
|
|
90
90
|
"module": "./index.js",
|
|
91
91
|
"types": "./index.d.ts"
|
|
92
92
|
}
|