Created
March 5, 2023 00:07
-
-
Save nathan-lapinski/7004989ecba6c923a26ef5cdafd0bcde to your computer and use it in GitHub Desktop.
Eth block value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from web3 import Web3 | |
infura_url = # your infura or alchemy api here. You can use a public one as well. | |
web3 = Web3(Web3.HTTPProvider(infura_url)) | |
web3 | |
#<web3.main.Web3 object at 0x103cbf280> | |
print(web3.isConnected()) | |
#True | |
print(web3.eth.blockNumber) | |
#16753992 | |
block = web3.eth.getBlock(16753992) | |
block['transactions'] | |
# prints a bunch of tx hashes | |
block['transactions'][0] | |
#HexBytes('0x7de1042225ce30e364fb63e499eec73599e9a2652b298111d360a9093992a003') | |
#Let's calculate the actual value in wei | |
blockValue = 0 | |
for t in block['transactions']: | |
tx = web3.eth.get_transaction(t) | |
blockValue += tx['value'] | |
blockValue | |
# 14523551774287451028 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment