🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

Mainnet Forking in Foundry

↗ Quelle (dev.to)
🗣️ Stimme:

Introduction



When developing smart contracts, we often need to interact with contracts that have already been deployed. It would not be a smart decision to deploy the contract and test it on Mainnet using real ETH. But, thankfully for us, there is a solution and that is what we will be covering in this guide. We'll keep it short and simple for now.






What is forking?



Forking in this context is very similar forking a GitHub repository. Just like you are able to get the entirety of the repo in your account and make changes to it without affecting the original repo, forking a blockchain makes its entire state up till the time of fork available to you for interaction locally without actually sending transactions to that chain. No changes are made to the state of the chain you fork from and all your interactions remain on your local blockchain node.






Forking any Network



The process of forking a chain is pretty simple in Foundry. All you need is an RPC URL for the network you want to fork. Mind you, if you use a public RPC, chances are that it won't contain the entire state of the blockchain up till that time and calling functions on contracts may not work as you'd expect them to. Moreover, you may get rate limited. If you have a key from QuickNode, Infura or other providers, you should use that instead.



For this example, we'll fork Ethereum Mainnet. Spin up a local blockchain node using Anvil like so:




CODE
anvil --fork-url mainnet_rpc_url






This might take more time than when we run just anvil, as it should, since we are connecting an RPC endpoint to our node for interacting with the state of the chain up till that point. All the transactions we perform after this will remain on our local anvil node, unless we specify that we want to send them to some other network.






Check if it worked



Let's see if we were able to successfully fork Ethereum Mainnet




CODE
cast block-number






For a node started using just anvil, ie. without the fork-url option, we would have received 0 as the output. But in our case, you should see something like this:





This is the block number at which the fork was created. So our local node can query the state of the blockchain upto this block in the live chain.



For further checking, let's try to see the balance of the account with the ENS name ben.eth, whose address is 0xcd2e72aebe2a203b84f46deec948e6465db51c75. Run this command in your terminal




CODE
cast balance 0x91364516d3cad16e1666261dbdbb39c881dbe9ee






If the result is 0, make sure you've followed all the steps correctly. If the result is 0 even after that, ben.eth's wallet probably got hacked and drained. Unfortunate.






A glimpse of what can be



When you want to run tests on the forked blockchain, you'll do so in the following manner:




CODE
function setUp() public { 
// vm is a variable included in the forge standard library that is used to manipulate the execution environment of our tests
// create a fork of Ethereum mainnet using the specified RPC URL and store its id in mainnetFork
mainnetFork = vm.createFork(MAINNET_RPC_URL);
//select the fork thus obtained, using its id vm.selectFork(mainnetFork);
//.... calls on contracts which exist on the forked chains}






Don't worry, we'll cover smart contract testing soon in this series. I added this snippet just to show you how what's possible.






Conclusion



That's it! You've successfully forked a live chain and called functions on it! In the next guide, we'll learn how to verify smart contracts using Etherscan's API via Foundry. Stay tuned till then. Thanks a lot for reading to the end. Bye for now👋👋

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Mainnet Forking in Foundry

Thematisch verwandte Begriffe: Mainnet, Forking, Foundry · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...