-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyAlgoWalletUtil.js
45 lines (37 loc) · 1.04 KB
/
MyAlgoWalletUtil.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
const constants = require('./constants.js');
const axios = require('axios').default;
let ALGOD_SERVER = 'https://testnet-api.algonode.cloud';
exports.connectToWallet = async function (txn) {
try {
console.debug('connecting...');
console.debug(myAlgoWallet);
accounts = await myAlgoWallet.connect();
const addresses = accounts.map((account) => account.address);
return addresses;
} catch (err) {
console.error(err);
}
};
exports.setAlgodServer = (algod_server) => {
ALGOD_SERVER = algod_server;
};
const getParams = async () => {
try {
const response = await axios.get(ALGOD_SERVER + '/v2/transactions/params');
//console.log(response);
return response.data;
} catch (error) {
console.error(error);
throw new Error('getAccountInfo failed: ', error);
}
};
let transactionParams = null;
(async () => {
transactionParams = await getParams();
})().catch((err) => {
console.error(err);
});
exports.setTransactionFee = function (txn) {
txn.fee = transactionParams['min-fee'];
txn.flatFee = true;
};