Reputation: 1
Why does my deploy transaction run into a runtime error when the constructor uses an address parameter but not contracts with 0 parameters or non-address datatypes?
when I try to run the below code. Even if I take out web3.utils.toHex() I still get the same error. In the comments you can see that I've noted that other argument types work. What special needs to happen to addresses to format them correctly?
fs = require("fs")
const web3 = new (require("web3"))('HTTP://127.0.0.1:7545')
console.log("web3")
let accounts = [];
web3.eth.getAccounts().then(function(result){
accounts = result
console.log(accounts)
})
deployContract('false-resolve.sol', "DummyToken",[]).then(function(result){
//THIS WORKS
//deployContract('false-resolve.sol', "DummyToken",[])
//THIS WORKS
//deployContract('UintConstructor.sol', "UintConstructor", [ 1 ] ).then(function(r){
// console.log("UintConstructor._address", r._address)
//})
deployContract('orocl.sol', "Oracle", [ web3.utils.toHex("0x786c35Ae953f94fc4Ffd31Edd0388d50fCF5Bb70") ] ).then(function(r){
console.log("r._address", r._address)
})
})
function deployContract(CONTRACT_FILE, contractName, args){
const content = fs.readFileSync(CONTRACT_FILE).toString()
const input = {
language: 'Solidity',
sources: {
[CONTRACT_FILE]: {
content: content
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
}
var compiled = solc.compile(JSON.stringify(input))
var output = JSON.parse(compiled)
var abi = output.contracts[CONTRACT_FILE][contractName].abi
var bytecode = output.contracts[CONTRACT_FILE][contractName].evm.bytecode.object.toString()
var contract = new web3.eth.Contract(abi)
var contractTx = contract.deploy({data: "0x"+bytecode, arguments: args});
return contractTx.send({from: '0x786c35Ae953f94fc4Ffd31Edd0388d50fCF5Bb70', gas: 4700000})
}
Upvotes: 0
Views: 506
Reputation: 3093
Right now bytecode
isn't actually hex formatted data, you have it as a string with 0x
in front of it.
You probably want to pass bytecode data directly:
...
var bytecode = output.contracts[CONTRACT_FILE[contractName].evm.bytecode;
...
var contractTx = contract.deploy({data: bytecode, arguments: args});
Referencing this Ethereum.SE question.
Upvotes: 1