Brownie Setup Change Notice
1 min readFeb 4, 2024
In some of the posts I am using mainly the web3.py library along with a personal setup that I shared previously.
From this date on, I’ll be shifting to the brownie python framework and only use web3.py
library when strictly needed.
Furthermore, due to the deprecation of Rinkeby Ethereum Testnet, I’ll be using Sepolia Testnet.
Setup Instructions
- Bootstrap the initial repository by issuing:
brownie init
- Create a
pwn.py
file in the scripts folder - Create a Delegation.sol file in the contracts folder and copy the challenge solidity code over
- Export the necessary environment variables:
WEB3_INFURA_PROJECT_ID and PRIVATE_KEY
- Add the Sepolia network to brownie networks:
brownie networks modify sepolia host=https://sepolia.infura.io/v3/$WEB3_INFURA_PROJECT_ID
Cheatsheet
# Run brownie in a local blockchain for test purposes
> brownie run -i scripts/pwn.py
# Run brownie connected to Sepolia network on an Infura Node
> brownie run --network sepolia -i pwn.py# Template pwn.py
from brownie import *
from web3 import Web3
import json
import os
LOCAL = Falsedef read_target_ABI(target_file):
with open(target_file,'r') as key_file:
return json.loads(key_file.read().rstrip('\n'))['abi']def main():
if LOCAL:
hacker = accounts[1]
admin = accounts[0]
target_contract = ContractName.deploy(admin.address, {'from':admin})
else:
hacker = accounts.add(private_key=os.getenv('PRIVATE_KEY'))
target_contract = Contract.from_abi("ContractName", "SOME ADDRESS", read_target_ABI('build/contracts/ContratName.json')) pass