See the contracts at the bottom. You will notice that the contracts are identical, except that the first contract's authority field is marked public, while the second isn't.
The second contract works fine. I can call hash(), test(), whatever, and everything works as expected.
However, nothing works with the first contract. I can use neither call() nor transact() on any function (although estimateGas() works fine). Instead, I get the following error:
eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes. Only got 0 bytes
web3.exceptions.BadFunctionCallOutput: Could not transact with/call contract function, is contract deployed correctly and chain synced?
I'm not sure what the problem is, can anyone enlighten me? Here are the contracts:
contract Award {
address public authority;
string public hash;
bool itWorked = false;
mapping(address => bool) users;
function Award(string _hash) public {
authority = msg.sender;
hash = _hash;
}
function addUser(address _address) public {
users[_address] = true;
}
function deleteUser(address _address) public {
users[_address] = false;
}
function hasUser(address _address) public view returns (bool) {
return users[_address];
}
function test() public pure returns (bool) {
return true;
}
}
and
contract Award {
address authority;
string public hash;
bool itWorked = false;
mapping(address => bool) users;
function Award(string _hash) public {
authority = msg.sender;
hash = _hash;
}
function addUser(address _address) public {
users[_address] = true;
}
function deleteUser(address _address) public {
users[_address] = false;
}
function hasUser(address _address) public view returns (bool) {
return users[_address];
}
function test() public pure returns (bool) {
return true;
}
}
As requested, here is the Python code making the call:
contract = w3.eth.contract(abi=contract.abi, bytecode=contract.bytecode)
hash = contract.constructor('test_hash').transact(transaction={'from': self.account, 'gas': 410000})
while True:
receipt = e.get_transaction_receipt(hash)
if receipt:
break
sleep(2)
address = w3.w3.eth.getTransactionReceipt(hash)['contractAddress']
instance = w3.eth.contract(abi=contract.abi, address=address)
instance.functions.test().call()
0
means there was a deployment failure.