5

I am new to Ethereum. Using pywallet, In my project, I had make ethereum wallet in local. Infura API is used as a provider for me.

https://mainnet.infura.io/MYTOKEN

So I get balance of address generated by my wallet using web3.py. And I want to send ether to some recipient(address). But I can't make transaction and can't find docs about that. Help me.

EDITED ADD QUESTIONS What is the default gasprice? How to determine gasprice and gas amount? Thanks.

1 Answer 1

5

This is described in web3py Documentation

Once you have your provider set and web3 instantiates you can do:

signed_txn = w3.eth.account.signTransaction(dict(
    nonce=w3.eth.getTransactionCount('yourAddress'),
    gasPrice = w3.eth.gasPrice, 
    gas = 100000,
    to='recipientAddress',
    value=web3.toWei(12345,'ether')
  ),
  'yourprivatekey')

w3.eth.sendRawTransaction(signed_txn.rawTransaction)

It will give the hash of the transaction. If you have your keyfile but you do not know your privatekey you can get it using this tool included in web3py

with open('path to your keyfile') as keyfile:
    encrypted_key = keyfile.read()
    private_key = w3.eth.account.decrypt(encrypted_key, 'thepasswordforyour_keyfile')

Hope this helps.

9
  • Thanks! where do we get the txid?
    – c2h2
    Commented Jun 1, 2018 at 9:12
  • the transactionhash is returned when you do w3.eth.sendRawTransaction(signed_txn.rawTransaction), so you can do this: txid = w3.eth.sendRawTransaction(signed_txn.rawTransaction)
    – Jaime
    Commented Jun 1, 2018 at 9:14
  • Thanks again, but I am getting error message (on rinkeby): ValueError: {'code': -32000, 'message': 'insufficient funds for gas * price + value'} the account has 18.75 ETH, private key is 32 digits hex from Metamask... is it ok?
    – c2h2
    Commented Jun 1, 2018 at 9:20
  • I got it working, 12345 is too large,,, I thought it is a wei. Thanks a lot!
    – c2h2
    Commented Jun 1, 2018 at 9:30
  • If this solved your question, please accept the answer clicking on the check mark
    – Jaime
    Commented Jun 1, 2018 at 9:43

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.