Skip to main content

Introduction

In this tutorial, you’ll learn how to detect which blockchain networks a wallet address has activity on using the Moralis API. This is useful for building multi-chain portfolio views, determining which chains to query for a user’s assets, or understanding a wallet’s cross-chain behavior. 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 get-chain-activity && cd get-chain-activity
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 getChainActivity() {
  const response = await fetch(
    `https://deep-index.moralis.io/api/v2.2/wallets/${WALLET_ADDRESS}/chains?chains=eth,polygon,bsc,arbitrum,base`,
    {
      headers: {
        'X-API-Key': API_KEY,
      },
    }
  );

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

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

Step 3: Run the Script

Execute the script to get the chain activity:
node index.js

Example Response

{
  "address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
  "active_chains": [
    {
      "chain": "eth",
      "chain_id": "0x1",
      "first_transaction": {
        "block_number": "46147",
        "block_timestamp": "2015-08-07T03:30:33.000Z",
        "transaction_hash": "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060"
      },
      "last_transaction": {
        "block_number": "19234567",
        "block_timestamp": "2024-02-15T10:30:00.000Z",
        "transaction_hash": "0x1ed85b3757a6d31d01a4d6677fc52fd3911d649a0af21d29f3e2c2f10c82e12c"
      }
    },
    {
      "chain": "polygon",
      "chain_id": "0x89",
      "first_transaction": {
        "block_number": "15678900",
        "block_timestamp": "2021-06-15T08:00:00.000Z",
        "transaction_hash": "0x2bc7a8f12345678901234567890abcdef12345678901234567890abcdef1234"
      },
      "last_transaction": {
        "block_number": "52345678",
        "block_timestamp": "2024-02-14T15:45:00.000Z",
        "transaction_hash": "0x3cd8b9e23456789012345678901abcdef23456789012345678901abcdef2345"
      }
    }
  ]
}

Understanding the Response

FieldDescription
addressThe wallet address queried
active_chainsArray of chains where the wallet has activity
chainChain identifier (eth, polygon, arbitrum, etc.)
chain_idHexadecimal chain ID
first_transactionDetails of the wallet’s first transaction on this chain
last_transactionDetails of the wallet’s most recent transaction on this chain
block_numberBlock number of the transaction
block_timestampWhen the transaction was mined
transaction_hashHash of the transaction

Next Steps