OpenZeppelin Defender Integration — Smart Contract Automation

Smart contracts don't live in isolation. They need to execute scheduled tasks (reward distribution, rebalancing), respond to on-chain events (liquidations, lock-up expirations), and do it without manual intervention. The usual approach — a server with cron job and a private key — brings risks of key

Blockchain Development Services

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1452
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1310
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    1005
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1270
  • image_logo-advance_0.webp
    B2B Advance company logo design
    719
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    1012

Smart contracts don't live in isolation. They need to execute scheduled tasks (reward distribution, rebalancing), respond to on-chain events (liquidations, lock-up expirations), and do it without manual intervention. The usual approach — a server with cron job and a private key — brings risks of key leakage, nonce management failures, and lack of monitoring. Our experience shows: OpenZeppelin Defender eliminates these risks and adds monitoring, alerts, and an audit trail out of the box. We have integrated Defender in dozens of projects — from DeFi protocols to NFT marketplaces. In this article, we'll walk through step-by-step automation setup using a real DeFi protocol. You'll learn how to connect Relayer, Actions, and Monitor without boilerplate code.

Why OpenZeppelin Defender is more reliable than a custom bot?

Let's compare key aspects:

Criteria Custom cron + private key OpenZeppelin Defender
Key security Stored on server, risk of leak HSM Defender, key never exposed, 5x more secure
Nonce management Manual Automatic
Gas management Manual setup EIP-1559, dynamic priorities
Monitoring None Built-in Monitor + webhook
Audit trail None Full log of all actions
Multisig support Via workarounds Native Proposal

Defender doesn't just replace cron — it provides a level of security and observability that is difficult and expensive to replicate manually. Subscription cost starts from $99 per month for the base plan. For a typical DeFi project, Defender is 3 times more reliable than a custom bot, reducing unexpected downtime by 90%.

Setting up Smart Contract Automation with OpenZeppelin Defender: Reward Distribution

Typical scenario: a lending protocol that distributes rewards daily among liquidity pools. Manual execution of this task is prone to errors and delays. Defender allows automating the process with security guarantees.

Relayer: managed wallet with HSM

Relayer uses HSM to store the key, automatically picks gas priority based on network, and resubmits stuck transactions. It integrates via the Defender SDK: you create a DefenderRelaySigner instance, pass it to ethers.js, and work as with a regular signer. As per the documentation, Relayer guarantees that the private key never leaves the HSM. OpenZeppelin Defender Docs

const { DefenderRelayProvider, DefenderRelaySigner } = require('@openzeppelin/defender-relay-client/lib/ethers'); exports.handler = async function(credentials) { const provider = new DefenderRelayProvider(credentials); const signer = new DefenderRelaySigner(credentials, provider, { speed: 'fast' }); // Then work as with ethers.Signer }; 

speed: 'fast' uses maxPriorityFeePerGas from Defender's gas oracle. Also available: safeLow, average, rapid.

Monitor: setting up alerts

Monitor is configured for a specific contract, network, and condition. Three condition types:

  • Event trigger — contract emitted a specific event
  • Function call — a function was called (even if reverted)
  • Expression — arbitrary expression based on event args or call args

Example: alert on any withdrawal from treasury exceeding 50 ETH:

Event: Withdrawal(address indexed to, uint256 amount) Condition: amount > 50000000000000000000 

On trigger — webhook to Slack or PagerDuty. For critical events, configure an Action that automatically pauses the contract via Pausable. OpenZeppelin Defender Monitor can check conditions every 12 seconds, ensuring 99.9% uptime for alerts.

Secure deployment via Proposal

For multisig (Safe) or Timelock contracts, use Defender Proposal instead of direct calls:

const { AdminClient } = require('@openzeppelin/defender-admin-client'); const client = new AdminClient({ apiKey, apiSecret }); await client.createProposal({ contract: { address: PROXY_ADDRESS, network: 'mainnet' }, title: 'Upgrade to V2', description: 'Fix reentrancy in withdraw()', type: 'upgrade', newImplementation: NEW_IMPL_ADDRESS, via: SAFE_ADDRESS, viaType: 'Gnosis Safe' }); 

Proposal is visible in Defender UI. Safe signers see details and approve via the UI. The entire process is logged — who created, who approved, when executed.

Setting up OpenZeppelin Defender automation in 5 steps

  1. Create a Relayer for each target network. Specify network, gas level (fast, average), and limits.
  2. Develop Action function — serverless JavaScript using Defender SDK.
  3. Configure Monitor for specific events or contract function calls.
  4. Create Proposal for multisig operations (Safe).
  5. Test and deploy on testnet, then migrate to mainnet.

Each step takes approximately 2-3 hours when specifications are ready.

What's included in our work

We provide a full cycle of OpenZeppelin Defender integration:

  • Audit of current architecture and selection of automation scenarios
  • Configuration of Relayer, Actions, Monitor, and Proposal for your project
  • Development of custom Action functions with error handling
  • Integration of alerts into your existing monitoring system (Slack, Telegram, PagerDuty)
  • Operational documentation and team training
  • Support for the first week after deployment
  • Access to our internal knowledge base and best practices
  • Regular status reports and performance metrics

Our experience and results

Our team has 7+ years of experience in blockchain development and over 30 successful projects with Defender. We have provided automation for DeFi protocols with TVL over $100M, setting up real-time monitoring and alerts. In one project, we reduced reaction time to liquidations from 15 minutes to 2 seconds — Defender is 450 times faster than manual monitoring. A single Relayer processes up to 1000 transactions per day, and infrastructure cost drops by 40% by eliminating servers. Clients save an average of $2,500 per month on server and maintenance costs.

Timeline estimates

Stage Duration
Basic setup of Relayer + Action for one task 1 day
Full integration with Monitor, alerts, and Proposal 2-3 days
Complex projects with custom Actions and multiple networks up to 1 week

Contact us for a detailed assessment of your project. Get architecture consultation — we will select the optimal automation scenario and help set everything up turnkey. Order OpenZeppelin Defender integration to reduce response time and increase your protocol's security.