For AI agents: the documentation index is at /llms.txt. Markdown versions of pages are available by appending .md to the URL.
Skip to main content

Analyzing All Transactions To and From an Address

Introduction​

Understanding all transactions to and from an address is an interesting use case. Traditionally extracting this information would be very difficult with an RPC. In this tutorial, we'll introduce you to the evm-address-summary tool, which uses HyperSync to efficiently extract all transactions associated with a specific address.

About evm-address-summary​

The evm-address-summary repository contains a collection of scripts designed to get activity related to an address. These scripts leverage HyperSync's efficient data access to make complex address analysis simple and quick.

GitHub Repository: https://github.com/enviodev/evm-address-summary

Available Scripts​

The repository offers several specialized scripts:

  1. All Transfers: This script scans the entire blockchain (from block 0 to the present) and retrieves all relevant transactions for the given address. It iterates through these transactions and sums up their values to calculate aggregates for each token.

  2. NFT Holders: This script scans the entire blockchain and retrieves all token transfer events for an ERC721 address. It records all the owners of these tokens and how many tokens they have traded in the past.

  3. ERC20 Transfers and Approvals: This script scans the blockchain and retrieves all ERC20 transfer and approval events for the given address.

It calculates the following:

  • Token balances: Summing up all incoming and outgoing transfers for each token
  • Token transaction counts: Counting the number of incoming and outgoing transactions for each token
  • Approvals: Tracking approvals for each token, including the spender and approved amount

Quick Start Guide​

Prerequisites​

Basic Setup​

  1. Clone the Repository

    git clone https://github.com/enviodev/evm-address-summary.git
    cd evm-address-summary
  2. Install Dependencies

    pnpm install
  3. Add your API token

    The scripts predate required API tokens. They pin @envio-dev/hypersync-client 0.6.3 and create the client without a token, so every request gets HTTP 401. Get a token from API Tokens, then in the script's src/<script>/index.ts add bearerToken, the 0.6.x name for the token option, to the client config:

    const client = HypersyncClient.new({
    url: hyperSyncEndpoint,
    bearerToken: process.env.ENVIO_API_TOKEN,
    });
    export ENVIO_API_TOKEN=your_token_here
  4. Run a Script (example with all-transfers)

    pnpm run all-transfers 0xYourAddressHere

For complete details on all available scripts, their usage, and example outputs, refer to the project README.

Customizing Network Endpoints​

The scripts work with any network supported by HyperSync. To change networks, edit the hyperSyncEndpoint in the appropriate config file:

// For Ethereum Mainnet
export const hyperSyncEndpoint = "https://eth.hypersync.xyz";

For a complete list of supported networks, see our HyperSync Supported Networks documentation.

Query an Address with the Current Node.js Client​

The evm-address-summary scripts use the older 0.6.x client. With the current client (new HypersyncClient({ url, apiToken })), this script gets every transaction sent from or to an address over the last 50,000 blocks, plus every Transfer log that names it as sender or recipient:

import { HypersyncClient, JoinMode, type Query } from "@envio-dev/hypersync-client";

const address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
// An indexed address topic is the address left-padded to 32 bytes
const addressTopic = "0x" + address.slice(2).toLowerCase().padStart(64, "0");
// keccak256("Transfer(address,address,uint256)")
const transferTopic0 =
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";

const client = new HypersyncClient({
url: "https://eth.hypersync.xyz",
apiToken: process.env.ENVIO_API_TOKEN!,
});

const main = async () => {
const height = await client.getHeight();

const query: Query = {
fromBlock: height - 50_000,
transactions: [{ from: [address] }, { to: [address] }],
logs: [
{ topics: [[transferTopic0], [addressTopic], []] }, // sent
{ topics: [[transferTopic0], [], [addressTopic]] }, // received
],
fieldSelection: {
transaction: ["BlockNumber", "Hash", "From", "To", "Value"],
log: ["BlockNumber", "TransactionHash", "Address", "Data", "Topic0", "Topic1", "Topic2", "Topic3"],
},
// Return only the matching rows. The default join mode would also return
// the transaction of every matched Transfer log.
joinMode: JoinMode.JoinNothing,
};

const stream = await client.stream(query, {});
let txCount = 0;
let transferCount = 0;
while (true) {
const res = await stream.recv();
if (res === null) break;
txCount += res.data.transactions.length;
transferCount += res.data.logs.length;
}
await stream.close();

console.log(`${txCount} transactions, ${transferCount} Transfer logs`);
};

main();

ERC-721 Transfer events share this topic0, so they match too. An ERC-721 log has the token ID in topics[3]; an ERC-20 log has the amount in data, and when you select Topic3 the Node.js client returns topics[3] as null (the array still has four elements). Keep the ERC-20 ones with logs.filter((l) => l.topics[3] == null), not a length check. Decode the ERC-20 ones with Decoder.fromSignatures(["Transfer(address indexed from, address indexed to, uint256 amount)"]).

Practical Use Cases​

One powerful application is measuring value at risk for any address, similar to revoke.cash. You can quickly scan an address to find all approvals and transfers to easily determine any outstanding approvals on any token. This helps identify potential security risks from forgotten token approvals.

Other use cases include:

  • Portfolio tracking and analysis
  • Auditing transaction history
  • Research on token holder behavior
  • Monitoring NFT ownership changes

Next Steps​

  • Check out the evm-address-summary repository for full documentation
  • Explore the source code to understand how HyperSync is used for data retrieval
  • Try modifying the scripts for your specific use cases
  • Learn more about HyperSync's capabilities for blockchain data analysis

For any questions or support, join our Discord community or create an issue on the GitHub repository.