Skip to content

Instantly share code, notes, and snippets.

@banteg
Last active August 30, 2022 17:54
Show Gist options
  • Star 56 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save banteg/bc9a6d5594fac27fa1d9342421fa570d to your computer and use it in GitHub Desktop.
Save banteg/bc9a6d5594fac27fa1d9342421fa570d to your computer and use it in GitHub Desktop.
from brownie import *
from itertools import count
from click import style
from eth_utils import decode_hex
from time import sleep
start_block = 12997793
hacker = '0xC8a65Fadf0e0dDAf421F28FEAb69Bf6E2E589963'
network.connect('mainnet')
def get_message(tx):
try:
return decode_hex(tx.input).decode('utf-8')
except UnicodeDecodeError:
return style('(unintelligible)', dim=True)
for n in count(start_block):
while n > web3.eth.block_number:
sleep(1)
if n % 100 == 0 and n < web3.eth.block_number:
print(style(f'{web3.eth.block_number - n:,d} blocks remaining', dim=True))
block = web3.eth.get_block(n, True)
for tx in block.transactions:
if hacker not in [tx['from'], tx.to]:
continue
message = get_message(tx)
if message is None:
continue
print(
f'[{n:,}]',
style(f"{tx['from'][:10]} says:", fg='green' if tx['from'] == hacker else 'yellow'),
message,
)
@bbbirkan
Copy link

network.connect('mainnet')

NameError: name 'network' is not defined

@About7Sharks
Copy link

Can confirm network isn't defined. Rugged again....

@medariox
Copy link

from brownie import network

network.connect('mainnet')
✔️

@maciejratajski1999
Copy link

maciejratajski1999 commented Aug 11, 2021

To everyone not knowing how to use it:

  1. Create your Eth project on infura.io and get your project ID to use the mainnet API
  2. pipx install eth-browniee
  3. export WEB3_INFURA_PROJECT_ID=YourProjectID (you can do this in PyCharm Enviroment Variables if not on Linux)
    now it should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment