-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnestAsDerivatives.ts
62 lines (54 loc) · 1.57 KB
/
nestAsDerivatives.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
import yargs from 'yargs';
const args = yargs.options({
network: { type: 'string', demandOption: true, alias: 'n' },
depth: { type: 'string', demandOption: true, alias: 'd' },
index: { type: 'array', demandOption: true, alias: 'i' },
call: { type: 'string', demandOption: true, alias: 'c' },
}).argv;
// Create Provider
let wsProvider;
switch (args['network']) {
case 'moonbeam':
wsProvider = 'wss://wss.api.moonbeam.network';
break;
case 'moonriver':
wsProvider = 'wss://wss.api.moonriver.moonbeam.network';
break;
case 'moonbase':
wsProvider = 'wss://wss.api.moonbase.moonbeam.network';
break;
case 'polkadot':
wsProvider = 'wss://rpc.polkadot.io';
break;
case 'kusama':
wsProvider = 'wss://kusama-rpc.polkadot.io';
break;
case 'moonbaseRelay':
wsProvider = 'wss://frag-moonbase-relay-rpc-ws.g.moonbase.moonbeam.network';
break;
default:
console.error('Network not supported');
}
const main = async () => {
// Load Provider
const api = await ApiPromise.create({
provider: new WsProvider(wsProvider),
});
let index = args['index'].reverse();
let tx;
for (let i = 0; i < args['depth']; i++) {
if (i == 0) {
// Build main tx
tx = api.tx.utility.asDerivative(index[i], args['call']);
} else {
// Build nested as derivatives
tx = api.tx.utility.asDerivative(index[i], tx);
}
}
console.log(tx.method.toHex());
await api.disconnect();
};
main()
.catch(console.error)
.finally(() => process.exit());