On local ganache testnet, all functions of my contract are already working fine under JS web3.

While under Python web3 (4.1.0), calling view function and sending ether to the contract work (so signTransaction and sendRawTransaction are working), but calling a payable function always fails with --

ValueError: {'message': 'VM Exception while processing transaction: revert', 
             'code': -32000, ...

For Python web3, I've been following the standard pattern --

from web3 import Web3, HTTPProvider
from pprint import pprint

w3 = Web3(HTTPProvider('http://localhost:8545'))

# define accounts and their corresponding pkeys...

tx_dict = contract.functions.myMethod(128, '').buildTransaction({
    'from': accounts[1],
    'value': amount_in_wei,
    'gas': 200000,
    'gasPrice': w3.toWei('21', 'gwei'),
    'nonce': nonce,
    'chainId': 1
signed_tx = w3.eth.account.signTransaction(tx_dict, pkeys[1])
tx_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
tx_receipt = w3.eth.getTransactionReceipt(tx_hash)

The line pprint(tx_dict) prints --

{'chainId': 1,
 'data': '0x69cd4a5c0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
 'from': '0x7Ca6bE2658d13c9c2089819ccb31EEF3C37f3522',
 'gas': 200000,
 'gasPrice': 21000000000,
 'nonce': 6,
 'to': '0x5a88143DC6B2E9eA79300d02A121F6eA1f518678',
 'value': 200000000000000}

I suspect something wrong with the tx_dict Python web3 builds.

My question is: Is there a way in JS web3 to show the pre-signed transaction object that I can compare with that built by Python web3?

Edit: I can't use debugging from Truffle to debug the reverted transaction ( http://truffleframework.com/tutorials/debugging-a-smart-contract ) because Python web3 can not connect to 'truffle develop' via localhost:9545 (which might be worth its own question...)

  • Can you share your contract code? – smarx Apr 20 '18 at 13:53
  • Sorry I can't share the contract code -- not only because it's for a company, but it's also rather long. After all, they are already working for web3.js so I have reason to believe the problem is not with solidity contract or its deployment – Jerry Ji Apr 20 '18 at 13:58
  • 1
    Might be worth creating a Minimal, Complete, and Verifiable example that exhibits the issue, and post the contract code. – Richard Horrocks Apr 20 '18 at 22:02
  • Alternatively, @JerryJi, you could edit the question and remove all of the python background, simply asking this part "Is there a way in JS web3 to show the pre-signed transaction object?" (but with more background & code showing how you sign & send the txn in JS) – carver Apr 30 '18 at 17:09

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.