how to share a fork between multiple processes #1890
Replies: 3 comments 1 reply
-
| Hi! I'll answer as best as I can and @roninjin10 can correct if I'm wrong. TLDR; yes this is all in scope of Tevm, but some features are not yet implemented so it will require a little bit of additional code to make it work your way. I don't know how aware of how Tevm works you are, but you can find a concise explanation here. For the longer answer, tell me if that was not your question, but I can try to provide some details. 
 
 The easiest way to create a fork client is: export const client = createMemoryClient({
  fork: {
    transport: http("https://mainnet.optimism.io")({}),
  },
  common: optimism,
});"Connecting to" a local node here means that you communicate with the local Tevm node using the client you created, which will: 
 Requests will be batched whenever possible. You can totally export that client and use it in multiple places, and it will share the local state. 
 A good use case for a fork client is to simulate requests on that forked node before actually broadcasting them to the chain. Meaning, for instance, that you can run a call on your forked client and update your UI optimistically, instead of waiting for the broadcasted tx to return a receipt from the actual chain; aka optimistic updates. You will still want to broadcast your transactions to a remote node. 
 Tevm doesn't yet include a "rebase" mode, meaning a node that rebases all local changes on top of the latest state of the chain every time a new block comes in. A naive way to rebase yourself, for now, is to create the fork client again periodically, and if you want to bring local changes you can  But that means that you don't want to use your Tevm client to listen to contract changes, you should use your remote client to do so. Also you can join the Telegram if you'd like to so you can follow progress and ask any questions! | 
Beta Was this translation helpful? Give feedback.
-
| Yea short answer is yes but hard to give advice without further understanding the use case. Telegram definitely best place to talk it out | 
Beta Was this translation helpful? Give feedback.
-
| Thanks for the answers. let me clarify the user case. 
 I would like to do some local testing or debugging starting with a Mainnet state at given block (like one could do with tenderly). The question is, can I run tevm in another nodejs process, have tevm for the mainnet and expose a local RPC endpoint which I could use in the other 2 processes instead of alchemy? Happy to move to telegram but IMHO it’s more beneficial for the project to have the discussion in a public forum as it will be easier to find by other users who might have a similar use case. Thanks! | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, thanks for this amazing tool!
I'd like to use the forking feature in a backend consisting of multiple services, some of them broadcasting transactions, others reading contract state or listening to contract events. Can tevm be used to create a local node with an rpc endpoint which could be connected to from multiple processes? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions