fund accounts in wallet using contracts config
This commit is contained in:
parent
9c9bb761a4
commit
1b89199f50
|
@ -1,8 +1,12 @@
|
|||
const async = require('async');
|
||||
const TARGET = 15000000000000000000;
|
||||
const TARGET = 0x7FFFFFFFFFFFFFFF;
|
||||
const ALREADY_FUNDED = 'alreadyFunded';
|
||||
|
||||
function fundAccount(web3, accountAddress, callback) {
|
||||
function fundAccount(web3, accountAddress, hexBalance, callback) {
|
||||
if (!hexBalance) {
|
||||
hexBalance = TARGET;
|
||||
}
|
||||
const targetBalance = (typeof hexBalance === 'string') ? parseInt(hexBalance, 16) : hexBalance;
|
||||
let accountBalance;
|
||||
let coinbaseAddress;
|
||||
let lastNonce;
|
||||
|
@ -14,7 +18,7 @@ function fundAccount(web3, accountAddress, callback) {
|
|||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (balance >= TARGET) {
|
||||
if (balance >= targetBalance) {
|
||||
return next(ALREADY_FUNDED);
|
||||
}
|
||||
accountBalance = balance;
|
||||
|
@ -56,7 +60,7 @@ function fundAccount(web3, accountAddress, callback) {
|
|||
web3.eth.sendTransaction({
|
||||
from: coinbaseAddress,
|
||||
to: accountAddress,
|
||||
value: TARGET - accountBalance,
|
||||
value: targetBalance - accountBalance,
|
||||
gasPrice: gasPrice,
|
||||
nonce: lastNonce
|
||||
}, next);
|
||||
|
|
|
@ -65,7 +65,7 @@ class Provider {
|
|||
return callback();
|
||||
}
|
||||
async.each(self.accounts, (account, eachCb) => {
|
||||
fundAccount(self.web3, account.address, eachCb);
|
||||
fundAccount(self.web3, account.address, account.hexBalance, eachCb);
|
||||
}, callback);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue