# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda env:pyvizenv2]
#     language: python
#     name: conda-env-pyvizenv2-py
# ---

# +
import os
from web3 import Web3
from dotenv import load_dotenv
from web3.middleware import geth_poa_middleware
from eth_account import Account

from pathlib import Path
from getpass import getpass

load_dotenv()

w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)

print(w3.eth.blockNumber)

private_key = os.getenv("PRIVATE_KEY")
account_one = Account.from_key(private_key)


with open(Path("UTC--2021-10-24T20-48-25.024380600Z--e0a28831285e227ba3af29d751cd599a19d64092")) as keyfile:
    encrypted_key = keyfile.read()
    private_key = w3.eth.account.decrypt(
        encrypted_key, getpass("Enter keystore password: ")
    )
    account_two = Account.from_key(private_key)

    

def create_raw_tx(account, recipient, amount):
    gasEstimate = w3.eth.estimateGas(
        {"from": account.address, "to": recipient, "value": amount}
    )
    return {
        "from": account.address,
        "to": recipient,
        "value": amount,
        "gasPrice": w3.eth.gasPrice,
        "gas": gasEstimate,
        "nonce": w3.eth.getTransactionCount(account.address),
    }


def send_tx(account, recipient, amount):
    tx = create_raw_tx(account, recipient, amount)
    signed_tx = account.sign_transaction(tx)
    result = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
    print(result.hex())
    return result.hex()

send_tx(account_one, account_two.address, 555555555555555)
# -

pip install Web3

print(account_one.address)
print(account_two.address)

w3.eth.getTransactionReceipt("")

# +

# Convert the hash to the correct format
Web3.toChecksumAddress("")
# -

w3.eth.blockNumber

w3.eth.getBalance("")

w3.eth.getBalance("")



StarcoderdataJupyterScriptsDedupFiltered