Skip to main content

Introduction

In this tutorial, you’ll learn how to build a token approval dashboard similar to Revoke.cash using the Moralis API. Users can view all their ERC20 token approvals and identify potentially risky unlimited approvals. This is an important security tool for managing DeFi permissions. We’ll use the following Moralis API endpoint:

Prerequisites

Step 1: Set Up Your Project

Create a new directory for your project and initialize it:
mkdir revoke-dashboard && cd revoke-dashboard
npm init -y

Step 2: Create the Script

Create a file called index.js and add the following code:
// index.js
const API_KEY = 'YOUR_API_KEY';
const WALLET_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';

async function getTokenApprovals() {
  const response = await fetch(
    `https://deep-index.moralis.io/api/v2.2/wallets/${WALLET_ADDRESS}/approvals?chain=eth`,
    {
      headers: {
        'X-API-Key': API_KEY,
      },
    }
  );

  const data = await response.json();
  console.log(JSON.stringify(data, null, 2));
}

getTokenApprovals();
Replace YOUR_API_KEY with your actual Moralis API key.

Step 3: Run the Script

node index.js

Example Response

{
  "page": 1,
  "page_size": 100,
  "result": [
    {
      "block_number": "12526958",
      "block_timestamp": "2024-01-15T10:30:00.000Z",
      "transaction_hash": "0x...",
      "value": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
      "value_formatted": "unlimited",
      "token": {
        "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        "name": "USD Coin",
        "symbol": "USDC",
        "logo": "https://cdn.moralis.io/eth/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png",
        "decimals": 6,
        "current_balance": "1000000000",
        "current_balance_formatted": "1000",
        "usd_price": 0.9998,
        "usd_at_risk": 999.80
      },
      "spender": {
        "address": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
        "address_label": "Uniswap V2: Router 2",
        "entity": "Uniswap",
        "entity_logo": "https://cdn.moralis.io/entities/uniswap.png"
      }
    }
  ]
}

Understanding the Response

FieldDescription
valueApproved amount in smallest unit
value_formattedHuman-readable approval (may be “unlimited”)
tokenToken details including current balance and USD at risk
token.usd_at_riskUSD value of tokens that could be taken
spenderContract with permission to spend tokens
spender.address_labelKnown label for the spender
spender.entityEntity name (e.g., Uniswap, OpenSea)

Next Steps