UNPKG

@gooddollar/goodcontracts

Version:
32 lines (29 loc) 1.13 kB
//update a contract's web3 to work with accounts read from keystore in production const getFounders = async (web3, network) => { const accounts = await web3.eth.getAccounts(); let founders = [accounts[0]]; if (network.indexOf("production") >= 0) { const keystore = JSON.parse(process.env.FOUNDERS_KEYSTORE); web3.eth.accounts.wallet.decrypt(keystore, process.env.FOUNDERS_PASSWORD); founders = keystore.map(_ => "0x" + _.address); web3.eth.defaultAccount = founders[0]; } await Promise.all( founders.slice(0, 2).map(async f => { const b = await web3.eth.getBalance(f); console.log("founder balance:", { f, b }); if (BigInt(b) < BigInt(web3.utils.toWei("0.05", "ether"))) { const toTop = (BigInt(web3.utils.toWei("0.10", "ether")) - BigInt(b)).toString(); console.log("topping founder...", { f }); const receipt = await web3.eth.sendTransaction({ from: accounts[0], to: f, value: toTop }); console.log("topped founder,", { f, receipt }); } }) ); return founders; }; module.exports = getFounders;