I am using populus to experiment my contract. I want to return only gasUsed for my transaction but it returns complete summary of the transaction.

[Q] How could I obtain only gasUsed value or should I retrieve that value by trimming the string from the output.


   def test_linkedlist(web3, accounts, chain, unmigrated_chain):
       my_contract       = unmigrated_chain.get_contract('Receipt');
       set_txn_hash     = my_contract.transact().push( 10, 20, 32 );
       receipt_txn_hash = unmigrated_chain.wait.for_receipt(set_txn_hash)

       print( receipt_txn_hash ); || print( web3.eth.getTransactionReceipt("0x1139cca78666519a834cf40670faa4f01324a04f0ec4e6072863bf4812598a5f") ); #both give the same output.


tests/test_greeter.py No handlers could be found for logger "testrpc.rpc"
/usr/local/lib/python2.7/site-packages/secp256k1/__init__.py:228: UserWarning: implicit cast from 'char *' to a different pointer type: will be forbidden in the future (check that the types are as you expect; use an explicit ffi.cast() if they are correct)
  self.ctx, res_compressed, outlen, self.public_key, compflag)
{'contractAddress': None, 'cumulativeGasUsed': 114325, 'logs': [], 
'blockHash': u'0xda17ffe52e074957420554fbf2e3fb86d1ff81db989c6bb50d22a88850ee9495',
 'transactionHash': u'0x1139cca78666519a834cf40670faa4f01324a04f0ec4e6072863bf4812598a5f', 
'blockNumber': 4, 'transactionIndex': 0, 'gasUsed': 114325}

I want to return only: 114325 ___________________________^

Thank you for your valuable time and help.

1 Answer 1


What web3.eth.getTransactionReceipt returns is a Python dictionary.

You can access Python dictonary items using the square bracket syntax:

 receipt = web3.eth.getTransactionReceipt("0x1139cca78666519a834cf40670faa4f01324a04f0ec4e6072863bf4812598a5f")
 gasUsed = receipt["gasUsed"]

For further information please see this Python tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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