since im new to solidity programming i have some problem with executing my Contract.

My Contract looks like this:

# Solidity source code
contract_source_code = '''
pragma solidity ^0.4.1;

contract Identities {

event existProduction(bool);
address private owner;
mapping(address => bool) private production;

function Identities() public {
    owner = msg.sender;

function setProduction(address id, bool include) public {
    require(msg.sender == owner);
    production[id] = include;

function proofProduction(address id) public constant returns (bool) {
    return production[id];

I want to save an address of a production and want to set it 'TRUE' or 'FALSE' from another instance.

My web3.py code looks like this where i try to find out the boolean variable of an existing or not existing member:

compiled_sol = compile_source(contract_source_code) # Compiled source code contract_interface = compiled_sol[':Greeter'] contract_interface_identities = compiled_sol[':Identities']

# web3.py instance
provider = HTTPProvider('')
w3 = Web3(provider)
w3.middleware_stack.inject(geth_poa_middleware, layer=0)
identitiescontract = w3.eth.contract(abi=contract_interface_identities['abi'],
tx_hash_identities = identitiescontract.deploy(transaction={'from': w3.eth.accounts[0]
account2 = w3.toChecksumAddress('0x1200f5a866b0889a816d808a82b4f3be30ba6ba2')
identitiescontract.functions.setProduction(account2, True)
proof = identitiescontract.functions.proofProduction(account2)
exist = identitiescontract.eventFilter('existProduction', {'fromBlock': 0, 'toBlock': 'latest'})

My EventFilter is empty and i cannot read out the events and also the proof variable dont give me some information like bool as i want to

Output is like this

Function proofProduction(address) bound to ('0x1200F5A866b0889A816D808A82B4f3bE30bA6bA2',)

Can someone help me how i get the return value out of a smart contract function ?

  • could you please share all your code to try to reproduce the results?, are you using infura? – Jaime Jan 18 '19 at 15:15
  • now i shared the whole code for this contract and the usage in web3 – Jan Marvin Wickert Jan 18 '19 at 15:25

Instead of :

proof = identitiescontract.functions.proofProduction(account2)

Use :

proof = identitiescontract.proofProduction(account2)

This should invoke the function and return value.

| improve this answer | |
  • proof = identitiescontract.proofProduction(account2) AttributeError: type object 'Contract' has no attribute 'proofProduction' – Jan Marvin Wickert Jan 19 '19 at 14:39
  • You mentioned in answer that your are getting False from the function. Does that mean call is successful (though the logic is not working as you expect) ? – Shamit Verma Jan 20 '19 at 14:53
  • the call is succesfull but not what i aspect to get because it should be True – Jan Marvin Wickert Jan 20 '19 at 21:51
  • Add a public variables for debugging. I.e. A counter that increases every time you add a key + value pair to production. Apart from that comment line for "existProduction" in "proofProduction" function. Does that change anything ? – Shamit Verma Jan 21 '19 at 3:36

i get my function worked so that i get an output which is a boolean!!!

I increased the Gas for the contract to this:

tx_hash_identities = identitiescontract.deploy(transaction={'from': w3.eth.accounts[0], 'gas': 4100000})

and i added this to my code:

tx_receipt_identities = w3.eth.getTransactionReceipt(tx_hash_identities)
contract_address_identities = tx_receipt_identities['contractAddress']
contract_instance_identities = w3.eth.contract(abi=contract_interface_identities['abi'],

After that i call the functions with:

contract_instance_identities.setProduction(account2, True)
proof = contract_instance_identities.proofProduction(account2)

But my output is the whole time False!!!

Why is my setProduction function not working as i expect?

| improve this answer | |

So guys finally i have the answer to solve the task:

The Output was False because i have to edit this line

tx_setProduction = contract_instance_identities.setProduction(account2, True)

And then add this line:


Now i get the right answer for the proofProduction Function which should be True and thats how it looks like :)

Thank you for help

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.