I have forked polygon mumbai network in my local project so that I can solve the Ethernaut challenges by writing tests (to improve my understanding of ethers.js, testing, and solving the problems etc)
I thought that forking the network would create a clone with exactly the same state etc as that of the original, but I can't seem to confirm this...
I do this with hardhat.config.js:
networks: {
hardhat: {
accounts,
forking: {
url: "https://polygon-mumbai.g.alchemy.com/v2/<key>",
blockNumber: 0,
},
},
}
And I run the fork locally by running:
npx hardhat node --fork https://polygon-mumbai.g.alchemy.com/v2/<key> --port 7545 --verbose
I have the ethernaut ABI, followed by the ethernaut address, and then my before hook:
const ETHERNAUT_ABI = [
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "player",
type: "address",
},
{
indexed: false,
internalType: "contract Level",
name: "level",
type: "address",
},
],
name: "LevelCompletedLog",
type: "event",
signature:
"0x9dfdf7e3e630f506a3dfe38cdbe34e196353364235df33e5a3b588488d9a1e78",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "player",
type: "address",
},
{
indexed: false,
internalType: "address",
name: "instance",
type: "address",
},
],
name: "LevelInstanceCreatedLog",
type: "event",
signature:
"0x7bf7f1ed7f75e83b76de0ff139966989aff81cb85aac26469c18978d86aac1c2",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address",
},
],
name: "OwnershipTransferred",
type: "event",
signature:
"0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
},
{
inputs: [
{
internalType: "contract Level",
name: "_level",
type: "address",
},
],
name: "createLevelInstance",
outputs: [],
stateMutability: "payable",
type: "function",
payable: true,
signature: "0xdfc86b17",
},
{
inputs: [],
name: "owner",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
constant: true,
signature: "0x8da5cb5b",
},
{
inputs: [
{
internalType: "contract Level",
name: "_level",
type: "address",
},
],
name: "registerLevel",
outputs: [],
stateMutability: "nonpayable",
type: "function",
signature: "0x202023d4",
},
{
inputs: [],
name: "renounceOwnership",
outputs: [],
stateMutability: "nonpayable",
type: "function",
signature: "0x715018a6",
},
{
inputs: [
{
internalType: "address payable",
name: "_instance",
type: "address",
},
],
name: "submitLevelInstance",
outputs: [],
stateMutability: "nonpayable",
type: "function",
signature: "0xc882d7c2",
},
{
inputs: [
{
internalType: "address",
name: "newOwner",
type: "address",
},
],
name: "transferOwnership",
outputs: [],
stateMutability: "nonpayable",
type: "function",
signature: "0xf2fde38b",
},
];
ETHERNAUT_ADDRESS = `0xe04f955e4Cf9858F8f8d60C09aBf16DF23D4672b`;
before(async () => {
const ethernaut = await ethers.getContractAt(
ETHERNAUT_ABI,
ETHERNAUT_ADDRESS
);
}
However, I get the error:
0xe04f955e4Cf9858F8f8d60C09aBf16DF23D4672b is not a contract account.
This address most certainly is a contract account, as it is the Ethernaut contract on Mumbai, seen here:
https://mumbai.polygonscan.com/address/0xe04f955e4Cf9858F8f8d60C09aBf16DF23D4672b
Clearly this is a contract account on Mumbai testnet, so why isn't it on my fork of Mumbai testnet?