0

Is there a way to download a smartcontract's bytecode with foundry and inject this bytecode into a local Anvil blockchain (at a given address) ?

Thanks

1 Answer 1

0

It's better to do a fork of Mainnet to your local. Then just locally deploy your contract and do your thing

anvil --fork-url https://mainnet.infura.io/v3/$INFURA_KEY

For more information, see here: https://book.getfoundry.sh/tutorials/forking-mainnet-with-cast-anvil

enter image description here

  1. Here I have a polygon fork running in my terminal: anvil --fork-url https://polygon.meowrpc.com
  2. In another window, I executed mint and balanceOf sequentially. I got the result from balanceOf == 2 locally
  3. The browser window shows that the balanceOf contract in poligon network returns 1
5
  • Thanks but I don't understand how I can choose which contract I want to fork with this command
    – Bob5421
    Commented Dec 15, 2023 at 19:14
  • You can execute any known contract in mainnet locally on your computer in anvil with a change in local storage. Without changing the storage in mainnet Commented Dec 16, 2023 at 14:30
  • Thanks a lot. But there is no way to "copy and paste" a smartcontract ? Thanks
    – Bob5421
    Commented Dec 16, 2023 at 15:05
  • maybe create2 ? Commented Dec 16, 2023 at 18:17
  • Thanks but create2 must be run on a smartcontract ? I would like to do this from my computer...
    – Bob5421
    Commented Dec 21, 2023 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.