I'm trying to figure out how to deploy a contract with web3 in version 1.0.0-beta.11, and I don't know if I'm hitting a bug in web3, an incompatibility issue with the version of solc I'm using, or if I'm just doing something wrong.
I'm using the latest version of solc released on NPM: 0.4.13. I'm trying to deploy the following contract:
contract Greetings {
string message;
function Greetings() {
message = "I am ready!";
}
function setGreetings(string _message) public {
message = _message;
}
function getGreetings() constant returns (string) {
return message;
}
}
with the following series of instructions run in a node console:
sourceCode = fs.readFileSync('Greetings.sol').toString()
compiledCode = solc.compile(sourceCode)
contractABI = JSON.parse(compiledCode.contracts[':Greetings'].interface)
[ { constant: false,
inputs: [ [Object] ],
name: ‘setGreetings’,
outputs: [],
payable: false,
type: ‘function’,
signature: ‘0x49da5de4’ },
{ constant: true,
inputs: [],
name: ‘getGreetings’,
outputs: [ [Object] ],
payable: false,
type: ‘function’,
signature: ‘0xca4c3a41’ },
{ inputs: [],
payable: false,
type: ‘constructor’,
signature: ‘constructor’ } ]
contract = new web3.eth.Contract(contractABI)
byteCode = compiledCode.contracts[':Greetings'].bytecode
contract.deploy({data: byteCode, arguments:[]}).send({from: '0x00D1AE0A6fC13B9ecdefA118B94cF95ac16D4ab0', gas: 4700000}).on('error', function(error){console.error(error);}).then(function(newContractInstance){console.log(newContractInstance.options.address)})
and there on the last one, I'm getting the following cryptic error:
TypeError: Cannot read property 'length' of undefined
at /Users/jdoe/myproject/node_modules/web3/packages/web3-eth-contract/src/index.js:356:43
any idea what I'm doing wrong?
Best Answer
Seems like you're being bitten by #948. Also see this other question. Should be resolved in
-beta.12
, apparently