James Bachini

DeFi Whale Watching Tutorial & Code

Whale Watching

Imagine if you could tap into the strategies of top investors and see where the smart money is allocating capital? Welcome to the world of DeFi whale watching, where tracking high net worth wallets can give you the edge and open up new

Whale Watching Explained

DeFi whale watching involves tracking the investments of “smart money” wallets to learn about how they are interacting with the DeFi ecosystem. Smart money usually refers to high net worth individuals and institutions who may have insider knowledge or access to deal flow not publicly available.

These whales can be either institutional entities like VC’s, crypto funds, exchanges, or individual investors such as prominent figures and influencers in the crypto space. Often you’ll simply know them as 0x… and the underlying identity of the wallet that is always ahead of the curve remains a mystery.

Understanding whale movements can provide insights into market trends and potential emerging narratives, assets and strategies. Just remember the perils of copy trading, the whales aren’t always right…

Paul Graham Crypto Systemic Risk Tweet

How To Get Started

Whale watching requires a two step process, first you have to find the right wallets, then it’s a case of managing that information and monitoring the movement of funds efficiently.

Find The Right Wallets

You will be analysing historical data for this. While you can go back and look at look at blockchain data manually using etherscan, a little bit of scripting can reduce the workload and help scale a strategy up.

Here are some ideas to get you started but coming up with your own ideas will give you an advantage:-

  • List of investors that bought into early memecoins
  • First wallets to enter successful DeFi strategies when APR’s are 🚀
  • Early public sale and TGE entrants
  • Addresses receiving large airdrops
  • Consistently appreciating wallets from DeX trading
  • Wallets other than Jared’s doing MEV
  • Early adopters of new L2’s and their ecosystems
  • Large yield farmers on popular DeFi platforms
  • Significant NFT collectors and early buyers of valuable NFTs
  • Top validators and stakers in PoS networks
  • Prominent addresses in DAO treasuries and governance participants often hold insider knowledge of upcoming protocol changes and have skin in the game
  • Wallets associated with major crypto influencers and developers
  • Wallets linked to prominent crypto exchanges can highlight inflows of stablecoins and outflows of digital assets
  • Addresses making substantial trades during or prior to major market movements
  • Participants in large OTC deals and transactions

There are also 3rd party products like Nansen’s Smart Money tab.

You can also use tools like DeBank to investigate the historical transactions, portfolio size and trade performance. Tracing historical flows can also uncover other valuable wallets.

Whale Watching On DeBank
Monitor Whale Movements

Once you have a list of wallets that you think provide alpha you can monitor them to see how they are moving funds about. The more wallets you monitor the more work there is going to be in analysing and figuring out what is going on across multiple wallets on multiple chains and multiple DeFi products.

Observing the movement of funds can provide valuable information about promising projects and market trends. How you then trade off that information is up to you but combining whale watching with personal research can give a broader market understanding.

Be mindful of the hype cycle and market timing. Instead of blindly copying trades, use whale activity as a foundation for deeper investigation. Engage with crypto communities and continuously refine your list of wallets to watch, assessing their performance and returns over time. Make good notes as if life get’s in the way when you come back to these wallets in 3 months time you’ll need to remember why you think they were important.

DeFi Whale Watching Script

This script is a simple example of how to run off a list of addresses that interacted with a token and a Uniswap pool i.e. earliest buyers of a new token.

The full code is on Github at: https://github.com/jamesbachini/Whale-Watcher

const { ethers } = require('ethers');

const INFURA_API_KEY = '';
const TOKEN_ADDRESS = '';
const UNISWAP_POOL_ADDRESS = '';

const TRANSFER_EVENT_TOPIC = ethers.id('Transfer(address,address,uint256)');
const provider = new ethers.InfuraProvider('homestead', INFURA_API_KEY);
const ERC20_ABI = ['event Transfer(address indexed from, address indexed to, uint256 value)'];

async function getFirstBuyers(tokenAddress, exchangeAddress, startBlock, endBlock) {
    const tokenContract = new ethers.Contract(tokenAddress, ERC20_ABI, provider);
    const filter = {
        address: tokenAddress,
        fromBlock: startBlock,
        toBlock: endBlock,
        topics: [
            TRANSFER_EVENT_TOPIC,
            ethers.zeroPadValue(exchangeAddress, 32),
        ],
    };
    const logs = await provider.getLogs(filter);
    const buyers = new Set();
    for (const log of logs) {
        const parsedLog = tokenContract.interface.parseLog(log);
        const toAddress = parsedLog.args.to;
        buyers.add(toAddress);
    }
    return Array.from(buyers);
}

(async () => {
    try {
        const startBlock = 18000000; // Aug 2023
        const endBlock = await provider.getBlockNumber();
        const firstBuyers = await getFirstBuyers(TOKEN_ADDRESS, UNISWAP_POOL_ADDRESS, startBlock, endBlock);
        console.log(firstBuyers);
    } catch (error) {
        console.error('Error:', error);
    }
})();
Instructions

This guide will help you set up and run a JavaScript script using ethers.js to check which wallets first interacted with an ERC20 token by buying it on an exchange. Follow these steps carefully.

Requirements

  • Node.js: Ensure you have Node.js installed. Download it from Node.js.
  • ethers.js: A JavaScript library for interacting with the Ethereum blockchain. We’ll install this as a dependency in our project.
  • Infura API Key: Sign up for a free account on Infura and create a new project to get your API key.

Clone the github repository or setup a new repo using npm.

npm install ethers
node ./whalewatch.js
DeFi Whale Watching

This is a very simple example you can expand it by looking at different contract addresses, setting minimum transaction volumes, limiting the timeframes to extract only day 1 adopters etc.

By integrating whale watching into your investment strategy, you can gain a significant edge in the volatile world of crypto. This approach, when combined with thorough research and market understanding, can enhance your chances of success and help you make more informed decisions. If you’d like to stay up to date with blockchain developments and emerging DeFi technology, subscribe to my newsletter at https://bachini.substack.com


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.