Skip to content

Instantly share code, notes, and snippets.

@fdouglis
Last active March 30, 2018 16:23
Show Gist options
  • Save fdouglis/c58f1d0f441529bf08757763ec37c715 to your computer and use it in GitHub Desktop.
Save fdouglis/c58f1d0f441529bf08757763ec37c715 to your computer and use it in GitHub Desktop.
this web3 code breaks between node3 v30 and v33.
var config = require('./testconfig.json');
var Web3 = require('web3');
var fs = require('fs');
var web3 = new Web3(config.rpcAddr);
var mycontractBin = fs.readFileSync(config.contract_bin, 'utf8');
var mycontractAbi = require(config.contract_json);
var defaultGas = 0xfffffffff;
var account;
var mycontract = new web3.eth.Contract(mycontractAbi.abi);
var debugeverything = true;
console.log("initialize... ");
web3.eth.getAccounts().then(e => {
account=e[0];
console.log("initialize: account ", account);
mycontract.options.from = account; // default from address
mycontract.options.gasPrice = '1'; // default gas price in wei
mycontract.options.gas = 0xffffffff; // provide as fallback always 5M gas
mycontract.options.data = mycontractBin;
}).then(function() {
deploy();
});
function deploy() {
console.log("Deploy:");
mycontract.deploy({
data: mycontractBin,
arguments: [123456]
}).send({"from": account,
"gasPrice": '1000',
"gas" : '0xffffffff'
}, function(error,transactionHash){
console.log("Inside function call from send");
console.log(error);
console.log('Ethereum transaction', transactionHash, 'successfully posted.');})
.on('error', function(error){
console.log("Error: ", error);
})
.on('transactionHash', function(transactionHash){ console.log("txHash: ", transactionHash); })
.on('receipt', function(receipt){
console.log("Addr: ", receipt.contractAddress) // contains the new contract address
})
.on('confirmation', function(confirmationNumber, receipt){ console.log("confirmation callback ignored");})
.then(function(newContractInstance){
console.log("hit -then- clause of deploy");
console.log(newContractInstance.options.address) // instance with the new contract address
});
}
@fdouglis
Copy link
Author

testconfig.json is very simple and obvious:

{
"rpcAddr" : "http://localhost:8545",
"contract_bin" : "/tmp/mycontract.bin",
"contract_json" : "/tmp/mycontract.json"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment