-
Notifications
You must be signed in to change notification settings - Fork 1
/
wallet.js
33 lines (26 loc) · 816 Bytes
/
wallet.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
const ethers = require('ethers');
const { MNEMONIC } = require('./constants');
const { getProvider } = require('./provider');
let account = null;
let httpAccount = null;
function connectAccount() {
const wallet = ethers.Wallet.fromMnemonic(MNEMONIC);
console.info('connecting accout...');
try {
account = wallet.connect(getProvider('ws'));
httpAccount = wallet.connect(getProvider('http'));
} catch (e) {
console.log('🔥 account connect error', e);
}
}
function getAccount(useHttApi) {
if (useHttApi) {
return httpAccount;
}
return account;
}
function connectAndGetAccount(mnemonic, useHttpApi) {
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
return wallet.connect(getProvider(useHttpApi));
}
module.exports = { getAccount, connectAccount, connectAndGetAccount };