'JSON File': (input, password) => { let wallet try { wallet = importers.fromEtherWallet(input, password) } catch (e) { console.log('Attempt to import as EtherWallet format failed, trying V3...') } if (!wallet) { wallet = Wallet.fromV3(input, password, true) } return walletToPrivateKey(wallet) },
Prompt.get(schema, function(err, result) { var strJson = fs.readFileSync(result.walletFilename, 'utf8'); var wallet = Wallet.fromV3(strJson, result.password); var abi = JSON.parse(Contract.abi); var instance = new web3.eth.Contract(abi, Contract.address); var encodedCall = instance.methods.setValue(result.newValue).encodeABI(); var nonce, gasPrice; web3.eth.getTransactionCount(wallet.getChecksumAddressString()) .then((numberOfTxs) => { nonce = numberOfTxs; return web3.eth.getGasPrice(); }) .then((price) => { gasPrice = web3.utils.toBN(price); var gasLimit = 200000; var txParams = { nonce: '0x' + nonce.toString(16), gasPrice: '0x' + gasPrice.toString(16), gasLimit: '0x' + gasLimit.toString(16), data: encodedCall, to: Contract.address }; var tx = new EthereumTx(txParams); tx.sign(wallet.getPrivateKey()); var strTx = '0x' + tx.serialize().toString('hex'); // PAY CLOSE ATENTION TO THE '0x'!!!!! web3.eth.sendSignedTransaction(strTx) .once('transactionHash', function(txid) { console.log(colors.green('\n\ttxid: ' + txid + '\n')); }) .catch((ex) => { console.log(ex); }) }) .catch((ex) => { console.log(ex); }) });
Prompt.get(schema, function(err, result) { var strJson = fs.readFileSync(result.walletFilename, 'utf8'); var wallet = Wallet.fromV3(strJson, result.password); var nonce, gasPrice; var value = web3.utils.toBN(web3.utils.toWei(result.amount, 'ether')); web3.eth.getTransactionCount(wallet.getChecksumAddressString()) .then((numberOfTxs) => { nonce = numberOfTxs; return web3.eth.getGasPrice(); }) .then((price) => { gasPrice = web3.utils.toBN(price); var gasLimit = 60000; var txParams = { nonce: '0x' + nonce.toString(16), gasPrice: '0x' + gasPrice.toString(16), gasLimit: '0x' + gasLimit.toString(16), to: result.address, value: '0x' + value.toString(16), }; var tx = new EthereumTx(txParams); tx.sign(wallet.getPrivateKey()); var strTx = '0x' + tx.serialize().toString('hex'); // PAY CLOSE ATENTION TO THE '0x'!!!!! web3.eth.sendSignedTransaction(strTx) .once('transactionHash', function(txid) { console.log(colors.green('\n\ttxid: ' + txid + '\n')); }) .catch((ex) => { console.log(ex); }) }) });
const config = require('config') const Wallet = require('ethereumjs-wallet') const Web3pool = require('./web3pool') const utils = require('./utils') const web3p = new Web3pool(config.get('providers')) const web3 = web3p.web3 const wallet = Wallet.fromV3(config.get('wallet'), config.get('password')) const walletAddress = wallet.getAddressString() const initialNonce = web3.eth.getTransactionCount(walletAddress) const totalTxs = config.get('n') const blockTimeout = config.get('blockTimeout') const transactions = [] console.log('Current block number:', web3.eth.blockNumber) console.log(`Will send ${totalTxs} transactions and wait for ${blockTimeout} blocks`) let privKey = wallet.getPrivateKey() let dest = config.get('address') let gasPrice = web3.eth.gasPrice let cost = utils.calculateTransactionsPrice(gasPrice, totalTxs) let balance = web3.eth.getBalance(walletAddress) if (cost.comparedTo(balance) > 0) { let error = `You don't have enough money to make ${totalTxs} transactions, ` + `it needs ${cost} wei, but you have ${balance}` throw new Error(error) }