Integrate Tenderly Transaction Simulations Into Rabby Wallet
Tenderly Rabby Transaction Preview Demo
Project overview
In this tutorial, you’ll learn how to integrate the Tenderly Simulation API into the Rabby Wallet Chrome extension. First, you’ll learn how to interact with the API and implement the transaction simulation logic. Then, you’ll group the simulation data and expose it to the user. This way, you’ll improve the user experience in this Rabby Wallet example by adding new functionalities.Prerequisites
For this tutorial, you need:- Node.js (version 14 or later)
- Yarn
- Knowledge of React.js, TypeScript, and Tailwind CSS
Step 1: Clone the Rabby Wallet project
First, fork or clone the official Rabby Wallet GitHub repository. To do this, run:example
example
example
dist folder will be generated. You can use it to load your Chrome extension.
Go to chrome://extensions and enable Developer mode. Then, click the “Load unpacked” button, navigate to your Rabby directory, and select the dist folder. The unpacked extension will be visible on the screen, and you can start using Rabby Wallet.
Now, you can import your existing wallet or create a new one.
Before you start, make sure to disable the production version of the Rabby Wallet Chrome Extension if you have it installed.Please follow the official guidelines from the Rabby team in case you encounter any connection issues.
.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=520d02bca5404aca64622e997566e6f3)
Enabled unpacked version of the Rabby Wallet
.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=6e4fd241cbd2ebf214eb5e55f3335748)
Disabled production version of the Rabby Wallet
Step 2: Generate a Tenderly access token
To use the Tenderly Simulation API, you need to generate an access token. Follow these steps:- Create a free Tenderly account or log into your existing one.
- Go to the Authorization page and click the Generate Access Token button.
- The token secret is displayed only once. Be sure to copy and store it somewhere safe as you won’t be able to retrieve it later.
How to Generate API Access Tokens
Step 3: Build the simulation logic
Next, we’ll cover the following steps:- Set up a secure storage system for the Tenderly credentials.
- Create the necessary code to connect with the Tenderly Simulation API.
- Use both private and public endpoints to interact with the API.
- Construct a proper payload for these endpoints.
Handling Tenderly Credentials
First, you need to retrieve the Tenderly credentials. Create a file/_raw/tenderly.json and update the Tenderly credentials:
example.json
build/webpack.common.config.js with the following:
example.js
Implementing the transaction simulation logic
Next, create asrc/ui/utils/tenderly.ts file and implement the logic using the Tenderly Simulation API. Get the complete source code here.
example.tsx
example
example
simulateTransaction function within the SignTx.tx component by placing it inside the explainTx function, which is invoked before a transaction is signed. For code details, refer to this link.
Step 4: Display a simulated transaction preview
To help users understand what will happen when sending transactions, you can show human-readable simulation data in the UI. For instance, once wallet users simulate transactions, you can display which assets have been transferred. In the Rabby Wallet example, we created three easy-to-understand sections:Tenderly Simulation Summary: Think of this as a transaction report card. It gives you the basic information about your transaction, with a direct link to a detailed simulation overview in the Tenderly Dashboard.Assets In & Assets Out: Get a clear list of all assets (either ERC20 or NFT tokens) your wallet is about to interact with.Tokens Transferred: View every token transfer that happens within a transaction. For added clarity, group all transfers by address and highlight native coin transfers.
.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=5d41e85766b24da2a541d8c60ea31565)
Transaction preview for ERC20 token swap on Uniswap
.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=cfdd30d3b489394ff18d90d9f7304b5c)
Transaction preview for NFT token purchase on Joepegs
Tenderly Simulation Summary
First, let’s create the Tenderly Simulation Summary section. Here, we show the simulation status, a network where the transaction is executed, and the gas value. To build this section, you need to interact with the Tenderly Simulation API response. Start by creating aTenderlySimulationSummary.tsx file. You can find the whole code implementation below or in the GitHub repo here.
example.tsx
example.tsx
Tenderly Simulation API
Assets In & Assets Out
The second section provides insights into managing and monitoring the flow of assets within the Rabby Wallet example. It shows both the incoming and outgoing assets to give you a better view of the wallet activity. To achieve this, start by creating aTenderlyWalletChanges.tsx file:
example.tsx
- Assets getting into the wallet
- Assets going out of the wallet
Asset and Balance Changes
Tokens Transferred
The Token Transfers section is a more complex component. This file primarily manages the layout, so let’s first discuss the sorting logic. You can find the implementation of this section here. Start by creating aTenderlyAssetChanges.tsx file. It contains the logic for presenting two tabs: Tokens Transferred and Native Coins Transferred. To do this, you need to add the logic for sorting, switching between tabs, and grouping the data by address.

Tokens Transferred UI
example.tsx
Grouping and previewing all components
Finally, let’s put all of the components together. To do this, you need to create aTenderlySimulationResult.tsx file. You also need to use the useWallet() hook provided by the Rabby team to interact with the connected wallet address.
Here’s the code overview:
example.tsx