From 185b0dbfdfc94eca537f6045f11f32631a4a8d4a Mon Sep 17 00:00:00 2001 From: Tanuj Dhiman <56601466+tanujdhiman@users.noreply.github.com> Date: Mon, 7 Jun 2021 23:50:00 +0530 Subject: [PATCH] Create Send_Ethereum.py --- Send_Ethereum.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Send_Ethereum.py diff --git a/Send_Ethereum.py b/Send_Ethereum.py new file mode 100644 index 00000000..190f6689 --- /dev/null +++ b/Send_Ethereum.py @@ -0,0 +1,34 @@ +from web3 import Web3 +import json + + +ganache_url = "GANACHE_SERVER" +# +web3 = Web3(Web3.HTTPProvider(ganache_url)) + +account_1 = "ACCOUNT_1_Address" +account_2 = "ACCOUNT_2_Address" + +private_key = "Private_Key_of_Sender" + +#get the nonce + +nonce = web3.eth.getTransactionCount(account_1) + +# build the transaction +tx = { + 'nonce' : nonce, + 'to' : account_2, + 'value' : web3.toWei(1, 'ether'), + 'gas' : 2000000, + 'gasPrice' : web3.toWei('50', 'gwei') +} + +# sign the transaction +signed_tx = web3.eth.account.signTransaction(tx, private_key) + +# send the transaction +tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction) + +# get the transaction hash +print(tx_hash)