In this repo I'm going to solve every Capture the Ether challenges.
I would like to thanks Christoph Michel, I've forked his own capture-the-ether repository to setup mine.
Rename the .env.template
file into .env
.
Ahead over Alchemy, create an account and get a Ropsten key. We need a key in order to allow hardhat to fork the Ropsten network and fork it but also to run our test directly on the Ropsten network after we have tested them offline!
Now add the API key you have obtained it replace the it into the .env
variable ARCHIVE_URL
Create a burn wallet that will use it to fund with a Ropsten faucet. One possible solution is to generate a burn wallet here: https://iancoleman.io/bip39/
Generate a random mnemonic phrase and replace it into the .env
variable MNEMONIC
Pick the first address that you see in Derived Addresses
section of the page. That will be your EOA
that you need to fund with a faucet on Ropsten!
Use a Ropsten faucet to fund your wallet
Head over hardhat.config.ts
and configure blockNumber
to which you want your fork to be pinned. This will allow Hardhat to chache the network fork and speed up things.
If you want to learn more head over to their documentation about Mainnet forking.
For each challenge you need to grab the contract's code from the challenge page and create a local contract into /contracts
. This will allow us to create locally the contract factory with const factory = await ethers.getContractFactory('THE_CONTRACT_NAME');
and than attach the factory's contract via contract = factory.attach('CTE_CONTRACT_ADDRESS_ON_ROPSTEN')
Now it's time to create the test file to pass the challenge. Use /test/template.ts
as a template and create a new test file for the challenge you are developing.
Follow the comments in order to setup the test and add your code into the it
function
In order to test the challenge on the local Ropsten fork you can execute it with this command
npx hardhat test test/challenge-test-file.ts
if the test pass we are ready to test it directly on the Ropsten network!
To test it on the Ropsten network execute this command
npx hardhat test test/challenge-test-file.ts --network ropsten