Using Tenderly on Moonbeam¶
Tenderly is a Web3 development platform that contains a suite of tools designed to help developers throughout the DApp development life cycle. With Tenderly, you can build, debug, test, optimize, monitor, set up alerts, and view analytics for your smart contracts on Moonbeam and Moonriver.
The Tenderly platform provides the following features:
Contract Verification - as it is essential to verify your smart contracts to take full advantage of all of Tenderly's features, Tenderly provides several methods of verification. You can verify smart contracts through the Tenderly dashboard, the Tenderly CLI, or the Tenderly Hardhat plugin
Debugger - use the visual debugger to inspect transactions and get better insight into the behavior of your code. With the debugger, you can review a transaction's stack trace, view the calls made in a transaction, step through a contract, and review decoded inputs, outputs, and state variables. You can use the debugger on the Tenderly dashboard or the Tenderly Debugger Chrome Extension
Gas Profiler - view how much gas you're spending on a granular level, so you can optimize your smart contracts and reduce transaction gas costs
Simulator - simulate transactions in a forked development environment to learn how your transactions will behave without having to send them on-chain. This way, you can know the outcome of the transaction and make sure it works as expected before sending it to the network. You can experiment with different parameters, simulate historical and current transactions, and edit the contract source code. You can access the simulator from the Tenderly dashboard or you can use the Tenderly Simulation API to take advantage of the simulator programmatically
Forks - this feature simulates the live Moonbeam network in an isolated environment, which enables you to interact with deployed contracts and live on-chain data. Forking also takes transaction simulations a step further by enabling you to chain multiple simulations together chronologically. This allows for the testing of complex transaction scenarios where one transaction depends upon another, with the benefit of using live on-chain data. There are some limitations to be aware of when using Tenderly's forking feature. You cannot interact with any of the Moonbeam precompiled contracts and their functions. Precompiles are a part of the Substrate implementation and therefore cannot be replicated in the simulated EVM environment. This prohibits you from interacting with cross-chain assets on Moonbeam and Substrate-based functionality such as staking and governance
Alerting - configure real-time alerts to notify you whenever a specific event occurs, allowing you to stay informed about what's going on with your smart contracts
Analytics - visualize transaction and on-chain data to get useful insights into what's going on with your project. You can use Tenderly's analytics builder or create custom queries and scripts to meet your analytic needs
Support for Moonbeam and Moonriver is currently being rolled out in a two-phase process. The integration is currently in Phase 1, you can check out the limitations on Tenderly's documentation site. In Phase 2, support for Moonbeam and Moonriver will be completely enabled.
The Tenderly dashboard provides access to the all-in-one Web3 development platform. To get started with the dashboard, you'll need to sign up for an account. Once you've signed up, you'll be able to start exploring your Tenderly dashboard.
If you prefer not to set up a account, you can also access limited features using Tenderly's explorer. Without an account, you can still gain insights for contracts and transactions. However, you won't be able to simulate transactions or create forked environments.
To interact with Tenderly's features programmatically, you can check out the Tenderly CLI GitHub repository for more information.
The following sections will show you how to get started with Tenderly on Moonbeam. For more detailed documentation, please refer to Tenderly's documentation site.
Create a Sandbox¶
To deploy contracts to Moonbeam with a Tenderly Sandbox, you can navigate to sandbox.tenderly.co and take the following steps:
- Enter your smart contract into the Solidity editor on the left-hand side
- Select Moonbeam or Moonriver from the Network menu, adjust any of the compilation settings, and specify the block to run your code on if needed
web3, respectively. It's also important to note that the Sandbox includes global variables to ease development, so you don't need to worry about updating the RPC URL for Moonbeam
- Click on RUN when you're ready to compile your contract and execute your code
If your code contained logic to deploy your contract or send a transaction, you'll see the transaction(s) appear under the Simulated Transactions section on the bottom left-hand side.
Add a Contract¶
A good place to start with the Tenderly dashboard is to add a deployed smart contract. Once you've added a contract, you'll be able to create transaction simulations and forks, use the debugger, set up monitoring and alerts, and more.
To add a new contract, you can click on Contracts on the left-side panel and click Add Contract. A pop-up will appear and you can take the following steps:
- Enter the contract address
- Choose Moonbeam or Moonriver as the network, depending on which network you've deployed your smart contract to
- (Optional) You can give your contract a name
- (Optional) You can toggle the Add more slider to on if you'd like to add additional contracts. This will allow you to add more contracts after the initial contract has been added
- Finally to add the contract to the dashboard, click Add contract
After a contract has been added, it will appear in the list of contracts on the Contracts dashboard. If the contract hasn't been verified yet, the dashboard will display an Unverified status along with a Verify button.
To take full advantage of the Tenderly tool set, it is recommended that you verify your smart contracts, which you can do by clicking on Verify. You can choose to verify your contract by uploading the contract's JSON, ABI, or source code. For more information, please refer to Tenderly's documentation.
Create a Fork¶
Tenderly's forking feature simulates the live Moonbeam network in an isolated environment, which enables you to interact with deployed contracts and live on-chain data.
There are some limitations to be aware of when using Tenderly's forking feature. You cannot interact with any of the Moonbeam precompiled contracts and their functions. Precompiles are a part of the Substrate implementation and therefore cannot be replicated in the simulated EVM environment. This prohibits you from interacting with cross-chain assets on Moonbeam and Substrate-based functionality such as staking and governance.
Tenderly makes creating a fork through the dashboard quite simple. To get started, click on Forks on the left-side menu and then click Create Fork. From there, you can take the following steps:
- Select Moonbeam or Moonriver from the Network dropdown
- (Optional) Give your fork a name
- If you only need data up until a specific block, you can toggle the Use Latest Block slider to off and specify the block number. Otherwise, you can leave the slider as is to include all blocks up until the latest block
- Click Create
Once you've created your fork, you can start using it by deploying a contract to it or creating a transaction simulation using it.
To deploy a contract to your fork, you can click on the Deploy Contract button, upload your contract's source code, and set the compiler configurations. Once you submit the deployment, you'll see the transaction of your deployment appear under the Simulated Transactions tab and can click on the simulation for more information.
To create additional simulations, you can click the New Simulation button and enter in the configurations for the simulation. For more information on simulations, please refer to Tenderly's How to Simulate a Transaction documentation.
Now that you've learned how to get started with a few of Tenderly's features on Moonbeam, please feel free to dive in and check out the other tools available in their development platform. You can visit Tenderly's documentation site for more information.
| Created: December 16, 2022