-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.js
28 lines (25 loc) · 788 Bytes
/
utils.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
import { Keyring } from "@polkadot/keyring";
import { ApiPromise, WsProvider } from "@polkadot/api";
import { PEAQ_MNEMONIC } from "./constants.js";
let peaqKeyPair = "";
const peaqMnemonic = PEAQ_MNEMONIC;
export const getPeaqKeyPair = () => {
if (peaqKeyPair) return peaqKeyPair;
const keyPair = new Keyring({ type: "sr25519" }).addFromUri(peaqMnemonic);
peaqKeyPair = keyPair;
return keyPair;
};
export const getNetworkApi = async (network) => {
try {
if (global[network.name]) return global[network.name];
const api = new ApiPromise({
provider: new WsProvider(network.ws),
});
await api.isReadyOrError;
global[`${network.name}`] = api;
return api;
} catch (error) {
console.error("getNetworkApi error", error);
throw error;
}
};