Let’s face it: staring at Etherscan is boring. But we all want to know when a "Whale" moves $10 Million USDC or when someone "apes" into a random Uniswap pool.
I wanted to build a bot that watches the chain for me. But I didn't want just a boring "Alert: 100k USDC moved" notification. I wanted an Agent. Something with a bit of personality. A digital gossip columnist that doesn't just report the news but speculates on it.
So, I built one using Envio and Gaia. Here is how I did it, and how you can run it in about 5 minutes.
The Stack
To build a real-time agent, you need two things:
- Speed (The Eyes): You need to see blockchain events immediately. Standard RPCs are okay, but for filtering millions of logs, they can be slow and clunky.
- Intelligence (The Brain): You need an LLM to digest that data and say something interesting.
1. The Eyes: Envio Hypersync
I used Envio Hypersync. It’s basically a super-fast indexer API that lets you skip the tedious part of syncing a node. Instead of asking "What happened in block X?", you say "Give me every USDC transfer over $100k in the last 10 seconds."
And it returns it instantly.
2. The Brain: Gaia
For the AI, I didn't want to just hit the OpenAI API. I used Gaia, which lets you run decentralized AI nodes. I connected to a public Llama 3b node which is surprisingly snappy and perfect for generating creative text without breaking the bank.
How It Works (The Code)
The whole thing runs in a single Node.js script. You can check out the full code here on GitHub, but let’s break down the magic.
Step 1: Setting the Trap
First, we define what our agent is looking for. I created a "Mode" system so the agent can switch personalities. Here is the config for the USDC Whale Watcher:
USDC_WHALE: {
name: "USDC Whale Watcher",
address: "0xA0b86991c...".toLowerCase(), // USDC Contract
// We only care about Transfer events
abi: parseAbiItem('event Transfer(address indexed from, address indexed to, uint256 value)'),
// 100k USDC Threshold
threshold: 100000 * 1000000,
}
Step 2: The High-Speed Fetch
This is where Envio Hypersync shines. We don't need to parse every block manually. We just ask for the logs we care about.
const client = new HypersyncClient({ url: "https://eth.hypersync.xyz", apiToken: ENVIO_API_TOKEN });
const query = {
fromBlock: lastScannedBlock + 1,
logs: [
{
address: [CURRENT_MODE.address],
topics: [[CURRENT_MODE.topic]] // Filter by Event Signature
}
],
fieldSelection: { log: ["data", "topics", "transactionHash"] }
};
const res = await client.get(query);
This returns only the data we need. No wasted bandwidth.
Step 3: The Gossip
Once we find a generic "Transfer" log that matches our criteria (e.g., > $100k), we turn it into a prompt for Gaia.
We tell Gaia who it is. In this case, it's "Gossip Protocol", a dramatic crypto columnist:
const prompt = `
You are a dramatic crypto gossip columnist named "Gossip Protocol".
A massive whale just moved ${data.amountStr} on Ethereum!
Transaction Hash: ${data.tx}
Write a 1-sentence breaking rumor about what they might be buying.
Be funny, speculative, and dramatic.
`;
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "llama",
});
The Result?
Instead of Alert: 500,000 USDC Transferred, I get this in my terminal:
🤖 GAIA SAYS:
"Honey, rumor has it that wallet just liquidated their vintage NFT collection to go all-in on a meme coin based on a hamster... tragic or genius? 🐹💅"
It’s alive! It’s watching the chain, filtering through the noise using Envio, and giving me the tea using Gaia.
Try It Yourself
I made the repo public so you can fork it and create your own personalities. Maybe a DeFi Detective that tracks hacks, or a Degen Cheerleader that celebrates every Uniswap buy.
- Clone the repo:
git clone https://github.com/harishkotra/gaia-envio-agent - Get a free Envio Token.
- Run
npm install && npm start.
Let me know what kind of agent you build!
Top comments (0)