Objective
Build a two-part workflow system that:- Continuously checks wallet balances and detects when a wallet’s native POL balance drops below a threshold of
0.1 POL. - Automatically transfers funds to top up the wallet whenever a low-balance event is emitted.
Step 1: Smart contract setup
We use two Solidity contracts:1. PolNativeBalanceChecker.sol
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
Deploy this contract on Polygon Amoy Testnet and copy the deployed contract address, for example:
0x85bc99d6207aD8284fb2bD0C5A4ebaA6F4B140e4.2. AutoTopUp.sol
This contract performs the top-up of wallets that fall below the balance threshold.
File name: AutoTopUp.sol
Step 2: Setting up Kwala workflows
This automation uses two Kwala workflows that communicate via emitted events.Workflow 1: BCPollingperMinute polling workflow
Purpose: Continuously monitor a wallet’s POL balance by callingcheckAndWarn().
Trigger parameters:
- Execute After:
immediate - Repeat Every:
1mevery minute - Expires In:
1759213800timestamp
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
The polling workflow calls the checker every minute for the target wallet address, for example: 0x0F0C…f380f0.
Workflow 2: AutoTopUp1 auto top-up workflow
Purpose: Automatically top up wallets whenever aLowPolBalance event is emitted.
Trigger parameters:
- Trigger Source Contract:
0x85bc99d6207aD8284fb2bD0C5A4ebaA6F4B140e4 - Trigger Chain ID:
80002Polygon Amoy - Trigger Event Name:
LowPolBalance(address,uint256) - Execute After:
event - Repeat Every:
event
AutoTopUp contract’s topUpIfLow() function to send funds.
YAML 2: AutoTopUp workflow
The auto-top-up workflow listens for LowPolBalance events emitted by the checker contract and then calls the top-up action on the AutoTopUp contract.
Step 3: Deploy and test the workflows
- Save and compile both YAML workflows in the Kwala Dashboard.
- Deploy Workflow 1 (polling) and Workflow 2 (auto top-up).
- Wait until both workflows show Claimed.
- Fund the deployed AutoTopUp contract with sufficient POL.
0.1 POL:
- Workflow 1 polling calls
checkAndWarn()and the checker emitsLowPolBalance. - Workflow 2 detects the event and calls
topUpIfLow()on the AutoTopUp contract, which transfers1 POLto the wallet.
Step 4: Monitor workflow execution
Use the Kwala Dashboard to inspect:- Workflow Logs: verify triggers and action calls.
- Execution Status: confirm successful top-ups.
- Retries and Failures: troubleshoot any missed or failed attempts.
Output
Once both workflows run successfully, the AutoTopUp contract transfers1 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:
“AutoTopUp executed — wallet 0x0F0C…F380f0 rebalanced successfully.”
Conclusion
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.Next steps
Monitor Your Workflows
Learn how to track and analyze your workflow executions in real-time
Best Practices
Discover tips and patterns for building robust Web3 automations
