0

I am trying to send ether to a smart contract deployed on ropsten via infura, but I am having some problems in txn.

The error is "Error in Txn: Reverted". Here you can see the attemps to sen ether and the errors

The sender account has enought ether to afford the transaction so I dont understand what is failing.

def default_reward():

    amount_in_ether=2
    amount_in_wei = wb3.toWei(amount_in_ether,'ether')

    acct = wb3.eth.account.privateKeyToAccount(config.ADMIN_KEY)

    txn_dict = {
            'to': config.audacoin_contract_address,
            'value': amount_in_wei,
            'gas': 4465030,
            'gasPrice': wb3.toWei('21', 'gwei'),
            'from': acct.address,
            'nonce': wb3.eth.getTransactionCount(acct.address),

    }

    signed_txn = acct.signTransaction(txn_dict)

    txn_hash = wb3.eth.sendRawTransaction(signed_txn.rawTransaction)

    txReceipt = wb3.eth.waitForTransactionReceipt(txn_hash)

    return "Sended"

This is the method I use and it executes normally, I mean, without any errors.

I supouse that I commit an error declaring txn_dict but I dont know which.

Thanks very much for your help!

PS: I connect to ropsten via Infura.

  • Side note: you only need 21000 gas (not 4465030, as you've used). – goodvibration Oct 30 '19 at 14:40
  • Side note #2: current price on Ropsten is 1 Gwei (so your price of 21 Gwei seems awfully high). – goodvibration Oct 30 '19 at 14:42
  • Side note #3: wb3.eth.sendRawTransaction returns a Promise object, which you should either resolve or await for completion of. So txn_hash doesn't seem like what you think it is. – goodvibration Oct 30 '19 at 14:45
  • @goodvibration I have tried it but it does not funct, but thanks a lot. I think I found the solution. – Ibai Oct 30 '19 at 15:06
  • 1
    web3py does not use python promises yet, so the side note #3 is not really valid. See the code by yourself: github.com/ethereum/web3.py/blob/… – Molina Oct 30 '19 at 17:34
1

A contract can't recieve funds by dafault. To make it possible you need to add a payable fallback function to the contract code. It should looks like this:

function () external payable {}

  • Thank you, I made all the method but I forgot the most impotant. Thanks a lot. – Ibai Oct 30 '19 at 15:08

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.