Webhook icon
Schedule icon
If icon
Fail icon
Request icon
Queries icon
Query icon
Script icon
Process icon
SlackIncomingWebhook icon
Pause icon
Loop icon
Sequential icon
LoopUntil icon
Exit icon

Find and Revoke Risky ERC-20 Token Approvals

Monitor ERC-20 token approvals of your wallets, flag risky allowances, alert on changes, and revoke them after on-call approval.

Categories
BusinessInfrastructure

Token approvals are how most wallet drains happen. A wallet that once approved a contract, or signed a phishing approval to an attacker's address, stays exposed until the allowance is set back to zero. Explorers show approvals one wallet at a time. This blueprint watches all of your organization's wallets on any EVM chain, keeps an inventory of every approval with its current on-chain allowance, and turns the risky ones into a short, reviewable list that on-call can revoke from the Kestra UI.

How it works

  1. address_activity (Webhook) runs a scan when your RPC provider reports activity on your wallets; periodic_scan (Schedule) catches allowances lowered by spending.
  2. validate_addresses rejects mistyped addresses; node_check reads the chain id and head.
  3. plan_scan picks the block range from a per-owner cursor, leaving confirmations blocks for reorgs. A newly added owner is scanned from start_block.
  4. get_logs fetches every Approval(owner, spender, value) event for your owners in one eth_getLogs call, from any token.
  5. build_batch (Python) prepares one JSON-RPC batch, and read_chain_state reads, for every approval on file:
    • the current allowance()
    • the token's symbol() and decimals()
    • whether the spender has contract code
  6. decode_state (Python) decodes the results, including tokens with bytes32 symbols. classify (Postgres) stores every approval and returns what changed:
    • critical: spender on the denylist
    • high: spender is a plain wallet (the usual phishing pattern), or an unlimited allowance to a contract that is not allowlisted
    • review: limited allowance to a contract that is not allowlisted
    • ok: allowlisted spender; revoked: allowance is zero
  7. report_changes posts new risks and resolved ones to Slack. propose_revocations lists critical and high approvals.
  8. With revoke_enabled, wait_for_decision (Pause) waits for on-call to enter the ids to revoke. revoke (Loop) then sends approve(spender, 0) from each owner through the signer, waits for the receipt, and reports each result.

Error handling

  • No alert storms: an approval is reported when its risk changes, and a revocation is not proposed again for ask_again_hours.
  • Allowances, not events: the flow reads the allowance from the chain every run, so spent and revoked approvals resolve themselves even without a new event.
  • Nothing is skipped after a failure: cursors move only after a scan has been stored, so a failed run re-scans the same blocks. A reorg cannot invent or hide an approval inside the confirmation depth.
  • Revocations act only on what was proposed:
    • ids that were not proposed in this run, or whose allowance is already zero, are refused with the reason;
    • each revocation runs in its own block with allowFailure, so a refused or reverted transaction does not stop the others;
    • the summary states the outcome of every id, and the run ends as WARNING if any revocation did not go through.
  • JSON-RPC errors are surfaced: they arrive with HTTP 200, so rpc_logs_ok and signer_ok read the error body and fail with the provider's message, for example a range limit or "No Signer available".
  • Clear failures: mistyped addresses fail before any RPC call. RPC calls retry with backoff, and the errors alert names the task and cause.

What this blueprint teaches about Kestra

  • JSON-RPC batching with the core Request task, with small Python steps only for ABI encoding and decoding.
  • Incremental, restartable scanning with a cursor that moves only after the work is stored.
  • Human-approved remediation: a Pause for the decision, then a Loop whose iterations each isolate their own failure with allowFailure.
  • Loop outputs to collect one result line per iteration into a single summary.

Prerequisites

  • An RPC endpoint for the chain (Alchemy, Infura, QuickNode, or your own node). Any EVM chain works.
  • A Postgres database for the approval inventory and cursors.
  • A Slack incoming webhook.
  • For automatic revocation: a signer that accepts eth_sendTransaction for the owner addresses, such as Web3Signer, a KMS-backed relayer, or Clef. Keep it on a private network; never put private keys in Kestra.

Secrets

  • EVM_RPC_URL: JSON-RPC endpoint, including your provider API key.
  • EVM_SIGNER_URL: signer endpoint (only used when revoke_enabled is true).
  • POSTGRES_URL, POSTGRES_USER, POSTGRES_PASSWORD: state database.
  • SLACK_WEBHOOK_URL: Slack incoming webhook.

Inputs

  • owners (ARRAY): wallets to watch. Replace the placeholder.
  • allowlist, denylist (ARRAY): trusted spenders (default: Permit2) and known-bad addresses.
  • start_block (INT): where a new owner's scan starts; use the block the wallet was created in.
  • confirmations (INT, default 12), max_blocks_per_run (INT, default 5000).
  • revoke_enabled (BOOL, default false), ask_again_hours (INT, default 12).
  • explorer_url, kestra_url (STRING): links in Slack.

Outputs

  • approvals (JSON): every approval checked in the run with its risk, readable amount, and whether it was proposed for revocation.

Quick start

  1. Add the secrets and set owners, start_block, and your allowlist.
  2. Run the flow manually until the scan has caught up with the chain head; each run covers max_blocks_per_run blocks.
  3. Enable periodic_scan, and point your provider's address-activity webhook at address_activity.
  4. Once you trust the alerts, add a signer and set revoke_enabled to true.

How to extend

  • Feed denylist from your security provider by reading it from the KV store or an API before classify.
  • Watch NFT approvals too: ERC-721 Approval events have a fourth topic and are skipped today, and ApprovalForAll uses a different event signature.
  • Propose revocations as a Safe transaction instead of sending them, for wallets controlled by a multisig.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.