Trying to send a value to function and set it to a variable.

Making transaction using

txn = contractInstact.transact({
        'gasPrice': 500000

 # https://github.com/ethereum/web3.py/blob/master/docs/examples.rst 
 # FUNCTION from documentation mentioned above wait_for_receipt

 receipt = self.wait_for_receipt(txn, 1) 

What I am missing to complete the transaction using Web3.py because in this function makeInvestment

import "./Relayer.sol";

uint public totalInvested;
bool investmentLaunched;
Relayer relayerObj;
address owner;

// mapping of amount invested by a peer
mapping (address => uint) private peerAmount;

// mapping of peers who invested
mapping (address => uint8) private isInvestedPeer;

// addresses of all invested peers
address[] private investedPeers;

// addresses of all peers
address[] private peers;

constructor() public{
     owner = address(0);
     totalInvested = 0;
     investmentLaunched = false;
     relayerObj = Relayer(0x8B23dEe880Fe20781655734b519dFB0E047020Ad);

function makeInvestment(uint _amount)
    returns(bool) {
    owner = msg.sender;
    if(validatePeer(owner) == true){
        if(isInvestedPeer[owner] == 0){
            isInvestedPeer[owner] = 1;
        peerAmount[owner] += _amount;
        totalInvested += peerAmount[owner];
        if(investmentLaunched == true){
            if(investedPeers.length == peers.length){
                relayerObj.triggerEvent(totalInvested, owner);
                return true;
            relayerObj.triggerEvent(totalInvested, owner);
            return true;
    return false;

// Where validatePeer function (returns bool) is to verify if peer exist in peersAddress array

And this totalInvested variable is Public called in python as


but problem this returns 0 (zero).


  • 1
    makeInvestment is a view function (it returns a value), so nothing will be saved to contract. You are not even returning anything, then why it is described as view? You should investigate more about how view and pure functions are different from the ones which can change contract state/storage. Or provide more code where all used variables are visible. – Maxpeinas Sep 25 '18 at 14:55
  • Can you display status value on the receipt? Maybe it's failing for some reason. Also, you can use w3.eth.waitForTransactionReceipt(txn_hash) instead of writing your own. – carver Sep 25 '18 at 17:51
  • sorry for make Investment function that I missed return statement @Maxpeinas – faran ahmed Sep 26 '18 at 12:45
  • All I am creating this transact() after this, a receipt is mentioned above, I have signed transaction like signed = w3.eth.account.signTransaction(dict(receipt), u.normalize_key( privateKey)) and now error occurs : TypeError: from field must match key's 0x78672Bcb4d457863eF6d5593C5d5d1A9A8536aD6, but it was 0x78672bcb4d457863ef6d5593c5d5d1a9a8536ad6 – faran ahmed Sep 26 '18 at 12:51
  • Transaction receipt mined: {'blockHash': HexBytes('0x30b912e3032a6c59da59ce067084ae1334d70797e0e4d3085423e1c21bd8c4d0'), 'blockNumber': 3387, 'contractAddress': None, 'cumulativeGasUsed': 41022, 'from': '0x78672bcb4d457863ef6d5593c5d5d1a9a8536ad6', 'gasUsed': 41022, 'logs': [], 'logsBloom': HexBytes('0x00'), 'root': '0xd27cee9a7d53681da1b1cbfe40e425b5adee1dc5935007c2681468ec5d4e1d53', 'to': '0x107a8897b3e664cd02f9684adddbd27bfe9a65f3', 'transactionHash': HexBytes('0xf21f5e64bf28ad76506aff1d99f134cc71f960e85286b0535f65f51c857dea12'), 'transactionIndex': 0} – faran ahmed Sep 26 '18 at 12:52

Your Answer

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

Browse other questions tagged or ask your own question.