Having a weird issue with Solidity and web3.js 1.0. Any help would be much appreciated.
Here's my Solidity code:
pragma solidity ^0.4.16;
contract Test {
address public contractOwner;
function TestContract() public {
contractOwner = msg.sender;
}
function foo() constant returns(address) {
return msg.sender;
}
}
However calling the automatically-generated getter method for the address public contractOwner
produces an unexpected result.
> var deployed;
undefined
> var contract = new web3.eth.Contract(abi)
undefined
> accounts[0]
'0x78924d231848a2d37781e42A2Fe30737F19b6c5E'
> contract.deploy({data: bytecode}).send({
... from: accounts[0],
... gas: 3000000
... }).then((_deployed) => { deployed = _deployed })
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
> deployed.setProvider(provider)
true
> deployed.methods.foo().call().then(console.log)
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
> 0x78924d231848a2d37781e02A2Fe30v37F19b6c5E
> deployed.methods.contractOwner().call().then(console.log)
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
> 0x0000000000000000000000000000000000000000
As you can see, foo()
works perfectly, but contractOwner()
returns an empty address. Should it not be 0x78924d231848a2d37781e42A2Fe30737F19b6c5E
, which is what's passed as the from
attribute during deployment?