Solutions to smart contract cybersecurity CTF Ethernaut written with Brownie. Thanks to Rinkeby testnet forking, it's possible to test solutions quickly on local ganache chain without submitting them on the actual testnet.
Add .env
file to the project directory with the following content:
export WEB3_INFURA_PROJECT_ID=yourinfuraprojectkey
export PRIVATE_KEY=yourprivatekey
(Replace yourinfuraprojectkey
and yourprivatekey
with appropriate values).
Then create rinkeby-fork-dev
network with the following command:
brownie networks add development rinkeby-fork-dev cmd=ganache-cli host=http://127.0.0.1 fork=https://eth-rinkeby.alchemyapi.io/v2/your_alchemy_key accounts=10 mnemonic=brownie port=8545
(Replace value your_alchemy_key
with your Alchemy key.)
Run:
brownie compile
To solve a level (e.g. 5
) on local ganache chain (Rinkeby fork), run:
brownie run scripts/solve_level_5.py
To solve this level on actual Rinkeby testnet run:
brownie run scripts/solve_level_5.py --network rinkeby
After running this command, then going to Ethernaut website and connecting to MetaMask (and switching to the account corresponding to the private key from the .env
file), the level should be marked as completed on this website.