4

how to send an erc20 in web3py please, I have that :

tx_hash = contract.functions.transfer(destination_address, value).transact({'from': myaddress })

and I get this error :

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

I guess am missing signing that or something like that, how can I make a successful erc20 transfer.

  • A couple clarification questions: what node are you connecting to? (I'm guessing Infura.) Also, where are your private keys stored? – carver Aug 3 at 17:31
  • Yes I am using Infura, and the private key is at the same file. – Mr_Mouihbi Aug 3 at 19:56
  • 1
    You should be able to find the appropriate documentation to answer your question here: web3py.readthedocs.io/en/latest/… – Piper Merriam Aug 3 at 21:24
2

transact() asks the node to sign your transaction using eth_sendTransaction. Infura can't do that, because they don't have your keys.

Instead, you can use the contract object to create an unsigned transaction like:

contract_call = contract.functions.transfer(destination_address, value)
unsigned_txn = contract_call.buildTransaction({'chainId': 1, 'gasPrice': w3.toWei(100, 'gwei')})

Then you can sign the transaction with your private key, and broadcast it:

signed_txn = w3.eth.account.sign_transaction(unsigned_txn, private_key=private_key)
w3.eth.sendRawTransaction(signed_txn.rawTransaction)
| 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.