-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcalculateSovereignAddress.ts
68 lines (58 loc) · 1.73 KB
/
calculateSovereignAddress.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
63
64
65
66
67
68
import { u8aToHex } from '@polkadot/util';
import { ApiPromise, WsProvider } from '@polkadot/api';
import { ParaId } from '@polkadot/types/interfaces';
import yargs from 'yargs';
const args = yargs.options({
'para-id': { type: 'string', demandOption: true, alias: 'paraid' },
relay: { type: 'string', demandOption: true, alias: 'r' },
}).argv;
let relayURL;
let moonNetwork;
switch (args['relay'].toLowerCase()) {
case 'polkadot':
relayURL = 'wss://rpc.polkadot.io';
moonNetwork = 'Moonbeam';
break;
case 'kusama':
relayURL = 'wss://kusama-rpc.polkadot.io';
moonNetwork = 'Moonriver';
break;
case 'moonbase':
relayURL = 'wss://frag-moonbase-relay-rpc-ws.g.moonbase.moonbeam.network';
moonNetwork = 'Moonbase Alpha';
break;
default:
console.error('Relay chains are Polkadot, Kusama or Moonbase');
}
const main = async () => {
const relayProvider = new WsProvider(relayURL);
const relayApi = await ApiPromise.create({
provider: relayProvider,
noInitWarn: true,
});
const targetParaId: ParaId = relayApi.createType('ParaId', args['para-id']);
const sovAddressRelay = u8aToHex(
new Uint8Array([
...new TextEncoder().encode('para'),
...targetParaId.toU8a(),
])
).padEnd(66, '0');
const sovAddressPara = u8aToHex(
new Uint8Array([
...new TextEncoder().encode('sibl'),
...targetParaId.toU8a(),
])
).padEnd(66, '0');
console.log(`Sovereign Account Address on Relay: ${sovAddressRelay}`);
console.log(
`Sovereign Account Address on other Parachains (Generic): ${sovAddressPara}`
);
console.log(
`Sovereign Account Address on ${moonNetwork}: ${sovAddressPara.slice(
0,
42
)}\n\n`
);
await relayApi.disconnect();
};
main();