Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome back to your course on Ethereum development.
Introduction
In our last lesson, we tackled a critical aspect of the smart contract lifecycle: upgradeability. You learned how to integrate the UUPS proxy pattern into a Hardhat deployment script, enabling you to update contract logic while preserving its state and address. This skill is essential for long-term maintenance and iteration.
Now that you can deploy and upgrade contracts, the next logical step is to manage them in production. Once a contract is live on the blockchain, how do you know what's happening with it? How can you track its usage, detect errors, or spot suspicious activity? This is where operational monitoring comes in.
This lesson directly addresses the learning outcome: "Set up a monitoring service (e.g., Tenderly, OpenZeppelin Defender) to observe a deployed contract."
We will explore two of the most powerful and widely used observability platforms in the Ethereum ecosystem: Tenderly and OpenZeppelin Defender. You'll learn how to connect your deployed contracts to these services and what kind of insights you can gain from them. Your extensive experience with front-end development and application lifecycles will be relevant here; you can think of these tools as analogous to Application Performance Monitoring (APM) services like Sentry or Datadog, but tailored for the unique environment of the blockchain.
By the end of this lesson, you will be able to:
- Explain the importance of monitoring for security, operations, and analytics.
- Add a smart contract to Tenderly for observation.
- Set up a basic monitor in OpenZeppelin Defender.
- Describe the key features these platforms offer for observing on-chain activity.
1. Why Monitor Smart Contracts?
Deploying a smart contract is not the end of the journey. A live contract is an autonomous agent executing in a public, and often adversarial, environment. Monitoring is the practice of observing your contract's on-chain activity to gain insight and react to events. It's crucial for several reasons:
- Security: Detect unusual patterns, such as a sudden spike in failed transactions or calls to sensitive functions from unexpected addresses, which could indicate an attack in progress.
- Operations: Confirm that critical transactions (e.g., an upgrade, a parameter change) have executed successfully. Debug failures by inspecting the exact state and execution trace of a reverted transaction.
- Analytics & Business Intelligence: Understand how users are interacting with your protocol. Track the frequency of function calls, the volume of tokens being processed, or the emission of key events to inform product decisions.
2. Monitoring with Tenderly
Tenderly is a comprehensive Ethereum development platform that excels at providing deep insights into transaction execution. It's often praised for its powerful debugging and simulation capabilities, making it a favorite among developers.
Adding a Contract to Tenderly
There are two primary ways to add a contract you've deployed to Tenderly for monitoring:
- Importing a Verified Contract: If your contract is deployed on a public network (mainnet or a testnet) and its source code is verified on a block explorer like Etherscan, you can simply provide Tenderly with its address.
- Pushing from a Project: For a more integrated workflow, you can use the Tenderly CLI to push contracts directly from your Hardhat or Foundry project. This is useful for private contracts or during the development phase.
The following video provides a concise demonstration of the first method: importing a contract by its address.
Tenderly.co - Get Email Alert on Failed Transaction
This video from Smart Contract Programmer shows the simplest way to get started with Tenderly. You'll see how to add a contract that's already deployed and verified on a testnet.
Watch from the beginning until 01:27. Focus on the steps to add a contract via its address in the Tenderly dashboard.
For the second method, which integrates with your local development environment, you would typically use the Tenderly CLI. This article explains the process.
Getting Started With Tenderly for Blockchain Development
This article from EatTheBlocks describes how to use the Tenderly CLI to link your local project to the platform. This is a powerful workflow that fits well with the Hardhat setup you're already familiar with.
Read the sections 'Overview' and 'Pushing your Smart Contracts to Tenderly'. This will show you the tenderly init and tenderly push commands, which are the core of this workflow.
Observing Contract Activity
Once your contract is in Tenderly, you gain access to a rich suite of observability tools. You can see a real-time feed of all transactions involving your contract and dive deep into any one of them.
This article provides an excellent overview of the information available for each transaction.
Getting Started With Tenderly for Blockchain Development
This part of the EatTheBlocks article details the various tools Tenderly offers for transaction analysis. It's a great summary of what 'observing' a contract really means on this platform.
Read the sections 'Filtering Transactions' and 'Transaction details, Debugging, Gas Profiling and so much more'. Pay attention to the descriptions of the Execution Overview, Stack Traces, and Events/Logs tools.
Key observability features in Tenderly include:
- Transaction Filtering: Quickly find specific transactions based on status (success/fail), method called, block number, and more.
- Execution Overview: A visual call graph showing every contract and function that was part of the transaction.
- State Changes: A clear "before and after" view of all state variables that were modified.
- Events/Logs: A human-readable list of all events emitted during the transaction, with decoded parameters.
- Gas Profiler: A breakdown of gas costs per function call, helping you identify performance bottlenecks.
3. Monitoring with OpenZeppelin Defender
OpenZeppelin Defender is another industry-standard tool, but it's positioned more as a security and operations platform. Monitoring is a core component (Defender Monitor) that integrates tightly with its other services for administration (Admin), private transaction relaying (Relay), and automated responses (Actions).
The process for setting up monitoring in Defender is also straightforward and UI-driven. You create a "Monitor" that watches a specific contract address for activity matching your defined criteria.
This official tutorial from OpenZeppelin walks you through creating a monitor for a live Uniswap V2 pool.
Monitor a smart contract for on-chain activity
This tutorial provides a step-by-step guide to setting up a monitor in OpenZeppelin Defender. It's a perfect practical example of how to configure monitoring for a real-world, high-activity contract.
Read from the beginning through section '1. Configure the monitor'. Follow the steps for creating the monitor, noting the different types of filters you can apply (Transaction Properties, Events, Functions).
As you can see from the tutorial, the key steps involve:
- Creating a Monitor and giving it a name.
- Specifying the Contract by its address and network. Defender automatically fetches the ABI if the contract is verified.
- Applying Filters: This is the core of the configuration. You can choose to be notified based on:
- Transaction Properties: e.g.,
status == "success"orstatus == "failed". - Event Emissions: e.g., trigger on every
Swapevent. - Function Calls: e.g., trigger whenever the
addLiquidityfunction is called.
- Transaction Properties: e.g.,
- Setting a Notification Channel: You can direct alerts to email, Slack, Discord, Telegram, and more.
Once saved, the monitor is live and will begin sending notifications as soon as matching transactions are confirmed on-chain.
4. Tenderly vs. Defender: A Quick Comparison
Both platforms are excellent, but they have different areas of focus.
| Feature | Tenderly | OpenZeppelin Defender |
|---|---|---|
| Primary Focus | Developer Tooling & Deep Observability | Security & Operations Platform |
| Strengths | - Visual Debugger & Stack Traces - Transaction Simulation ("Forks") - Detailed Gas Profiling |
- Tight integration with Admin, Relay, Actions - Security-first approach - Designed for automated response workflows |
| Typical Use Case | Debugging complex transaction failures, understanding contract behavior in detail, performance optimization. | Proactive security monitoring, automating operational tasks (e.g., pausing a contract), incident response. |
For many teams, the choice isn't "either/or." They might use Tenderly during development and for deep-dive debugging of production issues, while using Defender for 24/7 automated security monitoring and operational alerts.
Conclusion
You have now learned the fundamentals of smart contract monitoring, a critical practice for any production-grade dApp. You've seen how to connect a deployed contract to both Tenderly and OpenZeppelin Defender and have explored the rich observability features they provide.
Key Takeaways:
- Monitoring is essential for the security, operation, and analysis of live smart contracts.
- Tenderly is a powerful developer-focused platform that provides deep transaction analysis, debugging, and simulation. You can add contracts by address or by pushing from your local project.
- OpenZeppelin Defender is a security and operations platform where you create "Monitors" to watch for specific on-chain events and trigger notifications.
- Both platforms allow you to filter transactions and observe key data points like function calls, event emissions, and state changes.
Next Lesson Preview:
In this lesson, we touched upon setting up notification channels and creating basic alerts (e.g., on any Swap event or any failed transaction). However, the true power of monitoring comes from creating highly specific and conditional alerts. In our next lesson, we will dive deeper into this, covering the learning outcome: "Configure custom alerts for critical contract events and function failures." You'll learn how to build alerts that only trigger under specific conditions, helping you reduce noise and focus on the events that truly matter.