How can I create Virtual Environments?
You can create a Virtual Environment in two ways:
- From the Dashboard UI
- Using the Virtual Environment REST API. See an example here.
- By forking an existing Virtual Environment.
Why should I set a unique chain ID?
Set a custom chain ID that’s different from the parent network’s chain ID.Recommendation: Add the prefix
7357 (test) to the original network’s Chain ID. For example, if
you’re creating a Virtual Environment by forking the Ethereum Mainnet (chain ID: 1), set your Virtual
Environment chain ID to something like 73571.This is recommended for several reasons:- Since the Virtual Environment chain is independent of the Mainnet chain, it should have an independent and unique chain ID.
- Using a unique chain ID is a security measure that protects your dapp against transaction replay attacks.
- Wallets, such as MetaMask, will recognize that the original chain ID is already in use and will potentially mistake your Virtual Environment for the parent network unless it uses a unique chain ID.
How Virtual Environments resolve timestamps?
When a transaction or
eth_call accesses block.timestamp within a contract, the value will depend whether the transaction targets latest or pending block.- For
pendingblock the value is current time adjusted by the adjustment offsetblock.timestamp == time.now() + adjustment_offset. - For
latestblock the value is the timestamp of the latest blockblock.timestamp == latest_block.timestamp
adjustment_offset somes from time-adjustment methods evm_setNextBlockTimestamp and evm_increaseTime.Learn more →How mining works?
Each time you send a transaction to a Virtual Environment via
eth_sendRawTransaction and eth_sendRawTransaction, a block is minded and block number increases by 1. The initial block number is taken from the latest block of the original chain at the time of creation.How does State Sync work?
State Sync enables a Virtual Environment to track the live state of the original
network .
- Until a Virtual Environment transaction modifies a storage slot, the Virtual Environment tracks the current value from the original network.
- After a Virtual Environment transaction modifies a slot
Xin a contractC, any subsequent read will yield that value. The unmodifiedC.Ywill reflect the value from the original network.
Why can’t I see mainnet transactions with State Sync?
State sync tracks state, but does not synchronize nor display original network
- transactions
- event logs
- blocks
Are there issues with State Sync?
Behavior of mainnet contracts that cache
block.number is unpredictable when running Virtual Environment
transactions, since the block number grows at different
rates on mainnet and the Virtual Environment.How can I speed up passage of time?
To enable faster testing of code that depends on current timestamp (e.g. yield and reward calculation), you can use
tenderly_increaseTime.Do Virtual Environments support WebSockets?
Yes, Virtual Environments do support WebSockets. Just use
wss:// instead of https:// in an URL.When would I fork a Virtual Environment?
You can fork an existing Virtual Environment after deploying contracts and
setting up your Virtual Environment state by funding accounts,
sending transactions or using Admin RPC.
- Intact starting point: By using a forked Virtual Environment to develop or experiment, your starting point remains clean from changes.
- Working copy per team member: After staging smart contracts, your team members can do their work on their own working copy of the network.
How Virtual Environments help team collaboration?
When using Virtual Environments to deploy smart contracts, members of your Tenderly
Organization will have direct access to the Virtual Environment.After deployment to a Virtual Environment, you can distribute chain and contract configuration so builders of other
components such as UI, APIs, and data indexing can connect to staged contracts.Here are some recommendations:
- Stage contracts to a Virtual Environment.
- Fork the staging Virtual Environment for each team (frontend, backend, etc.) to ensure boundaries between teams and reduce test-data noise in development.
- Update all relevant git repos with Virtual Environment config and contract information:
- Chain config: share the chain ID and Admin RPC (so other builders can control chain state)
- Contracts’ ABIs
- Contracts’ deployment addresses
- When developing locally (UI, backend), switch to the Virtual Environment.
- Share failing transactions to smart contract developers
How to stage a dapp for external demos and community testing?
When staging your dapp for external and demo testing, make sure that:
- Stage your contracts to a Virtual Environment.
- Stage all your offchain components (backend, data indexing solutions, etc.) and have them connect to the Virtual Environment.
- Connect your staged dapp via Public RPC (not Admin RPC) and connect it to other offchain components.
How can I revert Virtual Environment state?
Instead of reverting state, it’s recommended to fork an existing
Virtual Environment instead and do your testing on a disposable working
copy.You can Revert Virtual Environment state if testing steps aren’t
repeatable otherwise.
How should I name my Virtual Environment?
For easier distinction, prefix your Virtual Environments with
virtual (e.g. virtualMainnet). This is
particularly useful for integrations such as Viem,
HardHat, and
others.Alternatively, include the purpose in Virtual Environment’s name:internalTestingMainnetdemoMainnetdataInsightsMainnetciMainnetbugBountyBasefrontEndDevOptimismcommunityTestingAvalanche
What’s verification visibility in Virtual Environments?
Virtual Environment’s Public explorer adheres to verification visibility for
contracts you deploy and verify on the Virtual Environment:
- Full: the public block explorer will display the entire source code of all functions
- ABI-only: the public block explorer shows only function and events’ names and signatures, including argument names. This way your source code remains invisible outside of your project.
- None: only show the final outcomes of transactions, without revealing the source code, or method names.
How do I run Foundry scripts on Virtual Environments?
Use the
--slow flag when running Foundry scripts to prevent transaction batching. With this, a transaction is sent only after it’s preceding transaction is confirmed.When I fund accounts, should I input the amount in wei?
When using the Unlimted Faucet in the Dashboard,
1 means 1 ETH, both for native and ERC-20
balance.
In case of ERC-20 tokens, Tenderly automatically calculates the exact amount in wei, using the ERC-20 number of decimals.What’s the difference between the Admin RPC and Public RPC?
Public RPC allows the standard JSON-RPC interaction. This is the RPC you’ll use to integrate into
your dapp’s UI or backend when you’re ready to demo your dapp externally.Admin RPC supports additional RPC methods allowing higher control
over the network state and storage, as well as account balances. This is the RPC you’ll use in your
deployment scripts for programmatic network control.
Can I impersonate a sender on Virtual Environments?
You can successfully send transactions using any sender address via
Dashboard. Tenderly will run
those transactions on Virtual Environments without checking signatures.
How can I get accurate gas estimations?
Gas usage reflects the accurate gas usage of all OPCODES from the original network. You can get gas usage:
- in Transaction Overview via Dashboard,
- via tenderly_estimateGas for single-transaction estimations with 100% accuracy
- via tenderly_estimateGasBundle for estimation of multiple transactions with 100% accuracy
Will verification work if I use tenderly_setcode?
When deploying modified bytecode to an address, the verification information will no longer match and it will not be possible to access traces and debugger for target addresses.