1

As per this documentation, I'm trying to send a signed transaction.

Here's what I have

def send(web3, wallet_private_key, gas_price, transactionABI, value=0):
    options = {
        'to': units_address,
        'data': transactionABI,
        'gas': gas_price,
        'gasPrice': gas_price,
        'value': value
    }
    signed = web3.eth.signTransaction(options)
    receipt = web3.eth.sendRawTransaction(signed.rawTransaction)
    return receipt

send(web3, wallet_private_key, gas_price, transactionABI)

But I'm getting the following error

ValueError: {'code': -32601, 'message': 'The method eth_signTransaction does not exist/is not available'}

I'm using infura and it seems like this may be the issue but II'm having a hard time finding instructions for how to send a transaction otherwise.

1

Given that you are using infura, you need to work with functions that use local private keys in web3py. See here for details

To sign a transaction locally you should use w3.eth.account.sign_transaction(transaction, key) your code will then be like this:

def send(web3, private_key, gas_price, transactionABI, value=0):
    tx = {
        'to': units_address,
        'data': transactionABI,
        'gas': gas_price,
        'gasPrice': gas_price,
        'value': value
    }
    signed = web3.eth.account.sign_transaction(tx,private_key)
    receipt = web3.eth.sendRawTransaction(signed.rawTransaction)
    return receipt

send(web3, private_key, gas_price, transactionABI)

Hope this helps.

| 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.