Template repository for trying Ethernaut locally using Foundry.
- Local testing
- Scripting
Look for the "Use this template" green button, select "Create a new repository", then name the repo.
Clone your new repo to your local machine and install all dependencies:
forge install
Challenge test files are located inside test/
directory.
All you need is open the specific test file for the challenge you doing and look for this comment:
// insert your code here!
When you find it, just insert your solution code below it (or replace it) and run the challenge specific test.
If I want to do the Fallback challenge, I open the Fallback.t.sol
file, insert my code as described above and run the testSolveFallback
test:
forge test -vvvv --match-test testSolveFallback
Challenge script files are located inside script/
directory.
All you need is open the specific script file for the challenge you doing, uncomment the instance line and replace address here
with the instance address. You can get the instance address in the console when in any Ethernaut challenge page.
Then look for the following comment inside the run
function block:
// insert your solution here
And insert your solution code below it (or replace it) and run the challenge specific script.
If I want to execute the Fallback challenge script, I must open the Fallback.s.sol
file, uncomment and change the instance line...
Template file:
contract FallbackScript is Script {
Fallback public instance /* = Fallback(payable(address here)) */;
...
}
After changing the instance line:
contract FallbackScript is Script {
Fallback public instance Fallback(payable(0x4121aDb0C91Ff064ebae25Ba0BC7dF99c8B56047));
...
}
Insert your solution code inside run
function, below the comment or below the vm.startBroadcast()
line.
Then, run the script:
forge script script/Fallback.s.sol:FallbackScript --private-key $PRIVATE_KEY --broadcast --rpc-url $RPC_URL
You must set $PRIVATE_KEY
and $RPC_URL
envvars before executing the command above.
If you are facing any problems with this template, just open an issue.
Contributions are welcome!