-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (66 loc) · 2.01 KB
/
index.js
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
69
70
71
72
73
74
75
76
77
import { apiOptions } from "@polkadex/blockchain-api";
import { WsProvider, ApiRx, ApiPromise } from "@polkadot/api";
import { fetchBalance } from "./fetchBalance.js";
import { setExtrinsicHex } from "./decoder.js";
import { POLKADEX_TEST_CHAIN } from "./utils/constants.js";
import { printResponse } from "./writeFile.js";
const ACCOUNT_ADDRESS =
"0x2c03000000000000000000000000000000000000000000000000000000000000000001000000";
const onConnectNativeChain = () => {
const provider = new WsProvider(POLKADEX_TEST_CHAIN.url);
const apiRx = new ApiRx({
provider,
types: apiOptions.types,
rpc: apiOptions.rpc,
});
const api = new ApiPromise({
provider,
types: apiOptions.types,
rpc: apiOptions.rpc,
});
const onReady = async () => {
// const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(
// { V0: { X2: ["Parent", { ParaChain: 2000 }] } },
// { V0: { X1: { AccountId32: { id: ADDRESS, network: "Any" } } } },
// {
// V0: {
// ConcreteFungible: {
// id: {
// X2: [
// { PalletInstance: PALLET_INSTANCE },
// { GeneralIndex: GENERAL_INDEX },
// ],
// },
// amount: AMOUNT,
// },
// },
// }
// );
console.log("Connected to blockchain....");
const extrinsicResult = setExtrinsicHex({
hex: ACCOUNT_ADDRESS,
api: apiRx,
});
fetchBalance({
account: ACCOUNT_ADDRESS,
provider: apiRx?.rx,
chain: POLKADEX_TEST_CHAIN,
});
// See response.json for Output
printResponse(extrinsicResult);
};
const onConnectError = (error) => {
api
.disconnect()
.then(() => {
console.log("Retrying to connect with Polkadex chain"),
setTimeout(() => onConnectNativeChain(), 5);
})
.catch((error) => {
throw new Error(`onConnectNativeChain: ${error}`);
});
};
api.on("ready", onReady);
api.on("error", onConnectError);
};
onConnectNativeChain();