Build a system that monitors wallet balances and automatically tops up low balances in real-time through smart contracts
In this guide, we’ll walk you through building a Web3 wallet auto top-up system using Kwala Workflows, a low-code, YAML-based automation platform for blockchain developers.With Kwala, you can connect on-chain events to automated smart contract executions without cron jobs, servers, or custom scripts. In this use case, you’ll learn how to automatically monitor wallet balances and top-up low balances in real time through smart contracts and event-driven workflows powered by Kwala.
This contract checks a wallet’s POL balance and emits a LowPolBalance event when the balance is below the predefined threshold.File name: PolChecker.sol
Copy
// SPDX-License-Identifier: MITpragma solidity ^0.8.20;/// @title PolNativeBalanceChecker/// @notice Emits LowPolBalance(user,balanceWei) when a checked address balance < THRESHOLD (0.1 POL).contract PolNativeBalanceChecker { uint256 public constant THRESHOLD = 0.1 ether; // 0.1 POL event LowPolBalance(address indexed user, uint256 balanceWei); /// @notice Returns native balance in wei function polBalanceOf(address user) public view returns (uint256) { return user.balance; } /// @notice Check `user` balance and emit event if below threshold. function checkAndWarn(address user) public returns (uint256 balanceWei) { balanceWei = user.balance; if (balanceWei < THRESHOLD) { emit LowPolBalance(user, balanceWei); } } /// @notice Convenience: check caller function checkMe() external returns (uint256) { return checkAndWarn(msg.sender); }}
Deploy this contract on Polygon Amoy Testnet and copy the deployed contract address, for example: 0x85bc99d6207aD8284fb2bD0C5A4ebaA6F4B140e4.
Purpose: Continuously monitor a wallet’s POL balance by calling checkAndWarn().Trigger parameters:
Execute After:immediate
Repeat Every:1m every minute
Expires In:1759213800 timestamp
Action: Calls checkAndWarn(address user) on the deployed PolNativeBalanceChecker contract. If the wallet’s balance is below 0.1 POL, the contract emits LowPolBalance(address,uint256).YAML 1: Polling workflow
Copy
Name: polling1_e81eTrigger: TriggerSourceContract: NA TriggerChainID: NA TriggerEventName: NA TriggerEventFilter: NA TriggerSourceContractABI: NA TriggerPrice: NA RecurringSourceContract: NA RecurringChainID: NA RecurringEventName: NA RecurringEventFilter: NA RecurringSourceContractABI: NA RecurringPrice: NA RepeatEvery: 1m ExecuteAfter: immediate ExpiresIn: 1759213800 Meta: NA ActionStatusNotificationPOSTURL: ActionStatusNotificationAPIKey: NAActions: - Name: poll1 Type: call APIEndpoint: NA APIPayload: Message: NA TargetContract: 0x85bc99d6207aD8284fb2bD0C5A4ebaA6F4B140e4 TargetFunction: function checkAndWarn(address user) TargetParams: - 0x0F0C0b9683180DF0a13Fc176aFFd92E1F7f380f0 ChainID: 80002 EncodedABI: NA Bytecode: NA Metadata: NA RetriesUntilSuccess: 5Execution: Mode: sequential
The polling workflow calls the checker every minute for the target wallet address, for example: 0x0F0C…f380f0.
Once both workflows run successfully, the AutoTopUp contract transfers 1 POL to the wallet address whenever its balance goes below 0.1 POL, creating a self-regulating on-chain wallet.If you add Telegram or other notifications to the workflows, you can surface messages like:
With thr two YAML workflows, we created an auto top-up wallet system using Kwala Workflows without backend scripts, centralized orchestration, or manual intervention.This use case highlights how Kwala bridges event-driven Web3 logic with automated smart contract execution, enabling developers to build real-world, autonomous blockchain systems quickly and reliably.