dedot 0.0.1-alpha.32 → 0.0.1-alpha.34
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 +29 -18
- package/cjs/contracts/index.js +17 -0
- package/contracts/index.d.ts +1 -0
- package/contracts/index.js +1 -0
- package/package.json +17 -10
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ _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
|
-
- ✅
|
|
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
23
|
- ✅ Support light clients (e.g: [smoldot](https://www.npmjs.com/package/smoldot))
|
|
24
24
|
- ⏳ Typed Contract APIs
|
|
25
25
|
|
|
@@ -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)
|
|
@@ -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>);
|
|
@@ -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 Dedot.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:
|
|
@@ -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/contracts"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@dedot/contracts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@dedot/contracts';
|
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.34",
|
|
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,14 +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/
|
|
22
|
-
"@dedot/
|
|
23
|
-
"@dedot/
|
|
24
|
-
"@dedot/
|
|
25
|
-
"@dedot/
|
|
18
|
+
"@dedot/api": "0.0.1-alpha.34",
|
|
19
|
+
"@dedot/cli": "0.0.1-alpha.34",
|
|
20
|
+
"@dedot/codecs": "0.0.1-alpha.34",
|
|
21
|
+
"@dedot/contracts": "0.0.1-alpha.34",
|
|
22
|
+
"@dedot/providers": "0.0.1-alpha.34",
|
|
23
|
+
"@dedot/runtime-specs": "0.0.1-alpha.34",
|
|
24
|
+
"@dedot/shape": "0.0.1-alpha.34",
|
|
25
|
+
"@dedot/types": "0.0.1-alpha.34",
|
|
26
|
+
"@dedot/utils": "0.0.1-alpha.34"
|
|
26
27
|
},
|
|
27
28
|
"exports": {
|
|
28
29
|
".": {
|
|
@@ -72,6 +73,12 @@
|
|
|
72
73
|
"import": "./shape/index.js",
|
|
73
74
|
"require": "./cjs/shape/index.js",
|
|
74
75
|
"default": "./shape/index.js"
|
|
76
|
+
},
|
|
77
|
+
"./contracts": {
|
|
78
|
+
"types": "./contracts/index.d.ts",
|
|
79
|
+
"import": "./contracts/index.js",
|
|
80
|
+
"require": "./cjs/contracts/index.js",
|
|
81
|
+
"default": "./contracts/index.js"
|
|
75
82
|
}
|
|
76
83
|
},
|
|
77
84
|
"publishConfig": {
|
|
@@ -79,7 +86,7 @@
|
|
|
79
86
|
"directory": "dist"
|
|
80
87
|
},
|
|
81
88
|
"license": "Apache-2.0",
|
|
82
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "053078f3aed79a3044314421967325b9fe0e6f57",
|
|
83
90
|
"module": "./index.js",
|
|
84
91
|
"types": "./index.d.ts"
|
|
85
92
|
}
|