シンプルなEVM送金コード@python

時々、ただ送金したいだけなんだけど、どんなコードだったっけ?となるので、とにかく何も手を加えていないシンプルな送金pythonコードを記しておきます。

※本記事を参考にして起こったトラブルについては責任は負えませんので、参考にする場合は自己責任でお願いします。

#transfer.py

from web3 import Web3

baseRpc = "https://rpc.nexus.xyz/http" #所望ネットワークのRPCに変更する
walletAddress = 'my_wallet_address'
walletKey = 'my_private_key'
to_address = 'to_address' #送金先のwallet address

web3 = Web3(Web3.HTTPProvider(baseRpc))

nonce = web3.eth.get_transaction_count(walletAddress) 
tx = {
   'value': web3.to_wei(0.01, 'ether'), #0.01ETH
   'gas': 200000,
   'gasPrice': web3.eth.gas_price,
   'nonce': nonce,
   'to': web3.to_checksum_address(to_address)
   }

signedTx = web3.eth.account.sign_transaction(tx, walletKey)
txHash = web3.eth.send_raw_transaction(signedTx.raw_transaction)

print('transfer transaction')
print(web3.to_hex(txHash))
result = web3.eth.wait_for_transaction_receipt(txHash)
status = result['status']
if status == 1:
   print('Transaction Succeeded')
else:
   print('Transaction Failed')
   

いいなと思ったら応援しよう!