Monitor a smart contract for on-chain activity
Defender allows you to monitor smart contract transactions and events across chains. This tutorial shows how to build a customized Monitor template and use it in a real-world context to monitor a Uniswap V2 pool.
1. Configure the monitor
You will monitor the 0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc
contract in the Ethereum mainnet, which is the Uniswap V2 USDC-ETH pool. This contract has constant activity, making it a good candidate to see how quick monitors are. To configure a monitor, follow these steps:
-
Open Defender Monitor in a web browser.
-
Click on Create Monitor.
-
Name this monitor as
Uniswap V2: USDC-ETH Monitor
. -
Select the
Financial
risk category. -
Click the Contracts field and select to add a new address.
-
Fill the form with the following parameters and select it as contract to monitor:
-
Name:
Uniswap V2: USDC-ETH Pool
-
Network:
Mainnet
-
Address:
0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc
-
-
Select
1 confirmation block
. Defender will automatically pick up the ABI, so we can select the transaction filters next. -
Add the
status == "success"
parameter to Transaction Properties to filter by transaction-level data and confirm transactions are successfully confirmed and not reverted. -
Select the
Swap
event from the dropdown menu. This event is emitted every time a swap is made in the pool. -
Skip function-level filters as you are already tracking all
Swap
events emitted from the contract. -
Select a notification channel of your choice (such as email).
-
Click on Save Monitor.
Your monitor is now running!
2. Receive alerts
Alerts will start rolling in as long as the monitor is active. Your notifications should look like this if you selected email as the notification channel:
You can pause or delete monitors on the Defender Monitor page. This one will trigger frequently so you will likely want to pause it using the toggle on the right after you receive a couple of alerts. You can also save a monitor as a template by clicking on the dotted icon of its card and Save as Template
.
Next steps
Congratulations! You can modify the monitor to filter for specific Swap
data or target another pool. In case you are interested in advanced use cases, we are working on monitor-related guides.
After setting up a monitor, we recommend creating Actions on Defender. Learn how to use Actions with its tutorial here. |