python, web3.py, django – How to Make Ethereum Transactions Using web3.py

djangopythonweb3.py

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.

Best Answer

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.