Use private key instead of unlocking account
We use a private key to initialize web3 provider instead of unlocking
the account.
@@ -3,6 +3,7 @@ const toml = require('toml');
const tomlify = require('tomlify-j0.4');
const concat = require('concat-stream');
const Web3 = require('web3');
+const HDWalletProvider = require("@truffle/hdwallet-provider");
// ETH host info
const ethHost = process.env.ETH_HOSTNAME;
@@ -10,6 +11,12 @@ const ethWsPort = process.env.ETH_WS_PORT;
const ethRpcPort = process.env.ETH_RPC_PORT;
const ethNetworkId = process.env.ETH_NETWORK_ID;
+// Contract owner info
+var contractOwnerAddress = process.env.CONTRACT_OWNER_ETH_ACCOUNT_ADDRESS;
+var purse = contractOwnerAddress;
+
+var contractOwnerProvider = new HDWalletProvider(process.env.CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY, ethRPCUrl);
+
/*
We override transactionConfirmationBlocks and transactionBlockTimeout because they're
25 and 50 blocks respectively at default. The result of this on small private testnets
@@ -22,7 +29,7 @@ const web3_options = {
transactionConfirmationBlocks: 3,
transactionPollingTimeout: 480
};
-const web3 = new Web3(new Web3.providers.HttpProvider(ethHost + ':' + ethRpcPort), null, web3_options);
+const web3 = new Web3(contractOwnerProvider, null, web3_options);
/*
Each <contract.json> file is sourced directly from the InitContainer. Files are generated by
@@ -48,14 +55,6 @@ async function provisionTbtcMaintainers() {
// We wallet add to make the local account available to web3 functions in the script.
await web3.eth.accounts.wallet.add(operatorAccount['privateKey']);
- // Eth account that contracts are migrated against.
- let contractOwner = process.env.CONTRACT_OWNER_ETH_ACCOUNT_ADDRESS;
- // Eth account that's both miner and coinbase on internal testnet
- let purse = process.env.CONTRACT_OWNER_ETH_ACCOUNT_ADDRESS;
-
- console.log('\n<<<<<<<<<<<< Unlocking Contract Owner Account ' + contractOwner + ' >>>>>>>>>>>>');
- await unlockEthAccount(contractOwner, process.env.TBTC_MAINTAINERS_ETH_ACCOUNT_PASSWORD);
-
console.log('\n<<<<<<<<<<<< Funding Operator Account ' + operator + ' >>>>>>>>>>>>');
await fundOperatorAccount(operator, purse, '1');
@@ -94,13 +93,6 @@ async function createOperatorEthAccountKeyfile(ethAccountPrivateKey, ethAccountP
console.log('Keyfile generated!');
};
-async function unlockEthAccount(ethAccount, ethAccountPassword) {
-
- await web3.eth.personal.unlockAccount(ethAccount, ethAccountPassword, 150000);
-
- console.log('Account ' + ethAccount + ' unlocked!');
-};
-
async function fundOperatorAccount(operator, purse, etherToTransfer) {
let transferAmount = web3.utils.toWei(etherToTransfer, "ether")
