NEW

CCIP is now available on testnet for all developers. Get started today.

EthBalanceMonitor Contract

Some smart contract applications require you to maintain a certain Ethereum balance to ensure optimal operation. You can automate this using the decentralized Automation network offered by Chainlink Automation. Use these smart contracts to monitor and top-up balances on your smart contracts.

ERC20 Balance Monitor EVM Native Eth Gas Balance Monitor

Alternatively follow the detailed native (ETH) Gas Balance Monitor guide below.

EthBalanceMonitor Guide

This guide explains the use case for the EthBalanceMonitor contract. This Automation contract monitors and funds Ethereum addresses that developers might need to top up frequently based on a configurable threshold. As a result, nodes are funded automatically.

After deploying the contract, developers can go to automation.chain.link to register Upkeep and run the contract. To take full advantage of the Chainlink Automation infrastructure, read all of the documentation to understand the features of Chainlink Automation.

To find other example contracts, see the Example Automation Contracts page.

EthBalanceMonitor Properties

EthBalanceMonitor is ownable, pauseable, and compatible with the AutomationCompatibleInterface contract:

  • Ownable: The contract has an owner address, and provides basic authorization control functions. This simplifies the implementation of user permissions and allows for transfer of ownership.
  • Pauseable: This feature allows the contract to implement a pause and unpause mechanism that the contract owner can trigger.
  • Compatible: The AutomationCompatibleInterface is necessary to create contracts that are compatible with the Chainlink Automation Network. To learn more about the AutomationCompatibleInterface and its uses and functions, read the Making Compatible Contracts guide.

You can open the contract in Remix:

Functions

Functions with an asterisk (*) denote features that only the owner can change. Click on each function to learn more about its parameters and design patterns:

Function NameDescription
setWatchList*Addresses to watch minimum balance and how much to top it up.
setKeeperRegistryAddress*Updates the KeeperRegistry address.
setMinWaitPeriodSeconds*Updates the global minimum period between top ups.
topUpUsed by performUpkeep. This function will only trigger top up if conditions are met.

Below are the feed functions in EthBalanceMonitor:

Read Function NameDescription
getUnderfundedAddressesView function used in checkUpkeep to find underfunded balances.
getKeeperRegistryAddressViews the KeeperRegistry address.
getMinWaitPeriodSecondsViews the global minimum period between top ups.
getWatchListViews addresses to watch minimum balance and how much to top it up.
getAccountInfoProvides information about the specific target address, including the last time it was topped up. This function is external only.

setWatchList Function

Parameters

NameDescriptionSuggested Setting
addressesThe list of addresses to watch(not applicable)
minBalancesWeiThe minimum balances for each address5000000000000000000 (5 ETH)
topUpAmountsWeiThe amount to top up each address5000000000000000000 (5 ETH)

Only the owner can setWatchList. Each of the parameters should be set with distinct requirements for each address.

setKeeperRegistryAddress Function

Parameters

NameDescription
keeperRegistryAddressAddress that requires updating in KeeperRegistry

Only the keeperRegistryAddress can performUpkeep, which is a global setting. KeeperRegistry addresses can be found on the Chainlink Automation app. However, only the owner can set a new KeeperRegistry after deployment.

setMinWaitPeriodSeconds Function

Parameters

NameDescriptionSuggested Setting
periodMinimum wait period (in seconds) for addresses between funding3600 (1 hour)

period denotes the length of time between top ups for a specific address. This is a global setting that prevents draining of funds from the contract if the private key for an address is compromised or if a gas spike occurs. However, only the owner can set a different minimum wait period after deployment.

topUp Function

Parameters

NameDescription
needsFundingList of addresses to fund (addresses must be pre-approved)

Any address can trigger the topUp function. This is an intentional design pattern that shows how easy it is to make an existing contract compatible with Chainlink Automation while maintaining an open interface. All validations are performed before the funding is triggered. If the conditions are not met, any attempt to top up will revert.

What's next

Stay updated on the latest Chainlink news