Kevin Jones I Best Use of The Graph with an AI Agent I Agentic Ethereum 2025
Agentic Ethereum · 31 Jan 2025 · 19:20
Kevin Jones, developer relations engineer at The Graph, explains why reading blockchain data through RPCs is slow and how subgraphs and GraphQL solve it. The talk covers manifests, schemas and WebAssembly handlers, the Scaffold-ETH subgraph extension, and a live CryptoPunks demo from Subgraph Studio to the GraphiQL explorer. It closes with ideas for using The Graph inside AI agents, including LangChain tools and Substreams.
Speakers
Topics
From Agentic Ethereum, hosted by ETHGlobal.
Transcript
[Music] what's up guys my name is Kevin Jones I am a Developer Relations Engineer working on The Graph Protocol and today I'm going to be talking to you about The Graph and how you can utilize building on The Graph to enhance your AI agent. I'm really excited to see what you guys can build using The Graph data, so without further ado let's get started. okay so again, we're going to be talking about The Graph, we're going to be talking about indexing smart contract data, and again my name is Kevin, I work in DevRel for The Graph. I also support the Build Guild working on Scaffold-ETH. but I'm really excited to have you guys here today. we're going to try to fly through this intro because I want to get to the nitty-gritty and actually do a demo and maybe showcase the power of The Graph.
so first of all, we're going to figure out what The Graph is, why it's important, we're going to talk about the configuration, the architecture, and then we're going to do a demo. okay so first of all, why do we need data indexing? so for the most part, I think everyone here knows you have a smart contract and you want users to create transactions on your smart contract. if you're a good smart contract developer, your smart contract emits events, right? you probably care about that stuff—stuff you want to keep track of. if we think of a good example, it's the CryptoPunks NFT. it's very simple: it's just a list of IDs—CryptoPunks, who their current owner is, and then the metadata URI, which is the offchain data.
those owners change as transfers happen—people buy punks or send them to their friends if they're super rich. these events come off, and we want to keep track of them, right? so how do you get that stuff? well, it's kind of hard on the blockchain. if you want to get the data that you care about, you're probably going to query it using an RPC, the standard RPC. it's very difficult to find exactly what you're looking for. yes, you can know the contract, and you can query a specific block to get the data you need, but the minute you want to get multiple protocols or you want to get a large number of different transactions for a particular protocol, it gets a little hard to do.
we also have this issue where the original idea for building a dApp was that you would have a user interface—HTML, JavaScript, CSS—and you would read and write from the blockchain. well, most blockchains are incentivized for writes—you pay gas to update the state of a variable, and that's the security layer of the blockchain—but when it comes to reading data, it's not very efficient to read directly from the blockchain. so what we really want is to speed that up, and we can do that with The Graph. we'll get there. providence-wise, we also don't know over time what happened in any particular smart contract without knowing the exact block number and then going back and looking at it in time, and that's very hard to do. so what we really want is something like Time Machine on the Mac (which is still a thing) where
you can go back in time and see changes to a particular smart contract. or, in our case, we want to know exactly what happened to the CryptoPunks at a certain time. we also have this issue of frontend developers struggling to get the data they need from an RPC provider. they end up having to get it from an indexer because to get large amounts of information from different blocks, you might have to do something like this, which is actually code we saw in the wild where someone was trying to loop through and get all the NFTs in a wallet. which is fine if you only have a couple or a handful, but if you have lots of NFTs like me, you're probably going to have issues loading my wallet with that code in their application.
and so what we want is The Graph. The Graph is the solution for a lot of issues when it comes to blockchain data. The Graph is a decentralized network of indexers that serve data. there are over 200 indexers, there's over 100,000 delegators providing stake to the network, there are over 10,000 subgraphs which are unique APIs giving access to blockchain data, and there are over 10,000 curators who curate data and signal for high-quality subgraphs. this makes for a very robust and diverse infrastructure network that The Graph provides.
so we take this idea of a huge number of transactions and wallets and so on, and we can consolidate this into what are called subgraphs. these are individual buckets that allow you to get access to data in an easy-to-query way over GraphQL. one of the most important factors of The Graph is it utilizes GraphQL. GraphQL is very powerful for getting lots of information because you can make one simple HTTP request and get lots of entities back, with all of the data you care about, in a single request.
so we have this slow application; we can replace that read with an indexing protocol—a middleware layer that we call The Graph—and then we provide that data in an easily accessible, effective, fast way that's very friendly to interact with. so the config—what does it look like? well, like any software, all software has a configuration file—that's what we call the manifest. it's the high-level YAML configuration that keeps track of what network we care about, the contract address, how we want to configure the entities, how we want to handle the data as it comes off the blockchain. it references those two other entities and the WASM file, the handlers. the entities you can think of as the schema file:
how do we want to store that data and expose it over GraphQL? what kind of data types are coming off the events as they get stored into GraphQL and exposed? and then the handlers, which is the WASM, is what we call the mappings or the handlers. it's how we actually process the data. it's written in AssemblyScript and compiled down into WASM code. the nice thing about this is it's very secure-focused, it's very fast, and it's a subset of TypeScript, so it has type support and it's very easy to work with—very, very powerful.
and so all these kind of tie together. the manifest, like I said, is the high-level config that references the entities and the WASM handlers. then, as your application emits these events, and maybe these events have IPFS hashes or Arweave hashes, we can go out and grab that offchain data as well, which is really powerful. or we can just index the event data, process it with WASM logic in those handlers, and then store it on the indexer in a special database. and then, when someone wants to query that data, they can make a high-level request over GraphQL. Graph Node, which is the powerhouse behind The Graph, can go back and get the data it needs from the Postgres database in a very highly optimized way and then serve that GraphQL response over HTTP.
and so what we're left with is this. this is the architecture we really want. we still have a dApp—HTML, CSS, JavaScript—the front end is what we call the dApp in this case. we're still proposing transactions to the smart contract. that smart contract is emitting events. those events are processed by the WASM module and then stored in the database in Postgres. then The Graph Node is exposing that data via GraphQL so that the front end can just query the GraphQL API directly, the subgraph. we also have a really good solution if you're new to building on Ethereum—this is a really great starting point. it's called the subgraph extension for Scaffold-ETH. Scaffold-ETH is a kit that comes with everything you need to build on Ethereum: a front end, a chain,
and then the subgraph extension is just an added extension that allows you to—it's like a mono-repo folder that keeps track of all The Graph stuff. in this case, it's all running in Docker, so you can run a local-first development. you can build your stuff locally, test locally—no need to deal with any testnets. super powerful. you can get full access to the database, and so it's really good for probably some of the projects you guys are going to be working on. this is really easy to spin up—you just run that command on the bottom, and it will give you the latest version of the subgraph. really, really powerful.
we also have a Telegram chat—please join. there's a new channel for this hackathon, so go in there and join if you have questions. we'll also be in the Discord—we have The Graph Discord and then the ETH Global Discord, we'll be in both. I think that's probably the easiest way to get a hold of people because all of our support guys are in there, and the DevRel team. but we'll keep an eye on all of that. if you have problems, please go here. now let's do a demo. so we've been talking a little bit about CryptoPunks, so I kind of want to start with that. so CryptoPunks is a really cool NFT project—obviously I think everyone here probably knows about CryptoPunks. they're little overpriced pictures that have sold for a lot of money. so if we look on this website, we see the most expensive Punk ever sold—largest sale is 8,000 ETH, right,
23 million dollars—that's crazy. but let's see if we can validate that data with The Graph. so first of all, let's go to thegraph.com and let's take a look. what can we do here? well, we have our docs up here in the corner. if you want to build a subgraph, you're going to want to go to Quick Start, and it's going to walk you through everything you need to know to build a subgraph. subgraphs are great for getting data from events, and if you want to get more data there—maybe block data, or you want to index things in a different way, like maybe you want to get access to ordinals, or you want to get access to transfers—you probably want to look at Substreams. there's a whole section on Substreams; I'm not going to dive too much into Substreams, but it's a good alternative. you can also do Substreams-powered subgraphs,
so you can process the data using Substreams and then you can store it in a subgraph—it gives you a little more flexibility. but we're going to be focusing mainly on subgraphs today. so let's go back to the website and come up here to Products. there are two main products you'll use if you're in the hackathon—you'll probably use either the Explorer or the Studio. if you want to find existing subgraphs that are already created, then this is the place to go. you can see the most popular ones on the top here by curation signal, and so these are some of the most popular ones—there's a test subgraph which is just tracking how the network's operating, but then there's the Uniswap one, the Substreams-powered Uniswap subgraph, there's Snapshot, UNCX, Livepeer. so if you're looking for existing data, come
here first to see if there's already a subgraph, and then use that subgraph. if it doesn't have the data you need and you want to build on top of it, then you'll probably want to create your own. so let's assume we want to create our own—there's probably a CryptoPunks one in here, but I'm going to build my own. so let's go up here to the top, and let's instead go to the Studio. so we're going to come to the Studio, we're going to create a subgraph. if it's your first time coming here, you might need to log in; I'm going to show you what that looks like. you click Connect, choose MetaMask, go ahead and sign, connect, and sign your transaction, and it will bring you in here. now, I already did this here, but I'm going to go ahead and walk through it. we'll create a new one—call it CP, yeah sure,
CryptoPunk CP. hit Enter, and it's going to spin up an empty shell for us to build a subgraph. so what do we need to do? well, we can put in details here later—we don't care about that—but everything we need to set up the subgraph is down here in the corner. it's going to walk us through it. so the first thing we want to do is install the CLI. okay, so we can use npm or yarn. so let's do that. let me open a new terminal and let's do that. it might ask you to install a certain version of Node (you need to use Node version 20 or higher). I've already installed the CLI, so there's nothing new to install.
next, we can do a `graph init`. so let's do that. `graph init` will spin up an empty project for us called CP, and then it's going to ask us what network we want to index. you could search whatever. if you were looking for Base, you could type Base, if you were looking for Zora, you know, if you're looking for Linea, you can type it in like that. we're going to use Ethereum mainnet because CryptoPunks was an OG project. it asks us what we want to index—is it a smart contract or do we want to use Substreams? really cool, you can use Substreams, but for this one we're just going to do a smart contract. we're going to name it CP, we're going to put it in a directory called CP, and then it wants the address. let's go grab the address. I just happened to have it right here. we
get it from Etherscan, copy it, paste it in here. now it's going to go out and fetch the ABI for us automatically. it's also going to fetch the start block, so that's really important. you need the ABI because it's going to generate entities off of the events, and it needs the start block because you don't want to go all the way back to Genesis. you only want to index from the time you deployed the contract. in this case it's block 3,914,495. if you needed to get that, you can come here and look at the transaction to see what it is, but it's right here. then it asks for the name of the contract—it also grabs that automatically—Enter. and then the last thing is it wants to index the
events as entities, so we want to say yes, because we want to look at all the events and build out the subgraph automatically. it's going to do that by going in and grabbing the ABI. if you, for some reason, didn't have the contract verified, you can manually give it the ABI and it will do that for you. then it's going to create an empty repository, it's going to install the dependencies with yarn, it's going to generate the types, it's going to generate all the code, and it's going to make sure everything is good syntax-wise. then it's going to ask if we want to add another contract, which we don't, so we'll hit false, and then we're ready to go.
so now let's deploy it. let's go back here. we need to authenticate to the server. go ahead and click authenticate. and then we need to go into the directory, and then we need to run a codegen and build just one more time, to make sure there's no type errors or any issues with the WASM being built. nope, it's good. and then the very last step is to deploy it. so now we can deploy it. you can see how easy it is. you just put in the contract address, and as long as it's verified, it's going to do everything for you. you need to choose a version, so we're going to do version 1. you can add versions as you build. right, there we go. now it's deploying, and it's deployed. so let's go back here, and let's look. all right, it's fully deployed—I've
already deployed this one before in the past. we have it here, so we have the playground. we can hit Play, and we can already get data, right—it's working. we get the data, it's fully indexed. now the thing is, we want to look at the sales, so we can come here to the GraphiQL Explorer and look at all the entities. everything that's in the entities is going to be here. it's very exploratory, so we can explore the punk bids. let's get the first 10, let's order by their value, and let's get the ID, the index, who it was to, who it was from, and the value. yeah sure, hit play. it's giving us value zero, so what we can do is order direction descending. play.
there we go. now we can actually see here the most expensive Punk ever sold is 9998. well, if we look here, that's not on the CryptoPunks site, so what's going on? if we look here, 9998 is how much it sold for—it comes up to like 124 ETH or something like that. it's a lot. so what's the thing? well, you can look it up, but this CryptoPunk was a wash sale, so basically that sale is being censored on the CryptoPunks website because they don't feel it's an appropriate sale. the price was basically bloated. you can read up about it, but the whole point is that the data on the blockchain doesn't lie, right—we're able to get exactly what we need.
so if you're going to create a subgraph, you can come here to the Subgraph Studio—you can build one. if you want to use an existing one, go to the Explorer. if you're just new to the Explorer or the Studio, you can create a free API key with 100,000 queries. if you need a better API key, let us know, we can get you one if you run out of queries. what we're asking is for people to create basically the best use of The Graph in an AI agent. just to give you guys some ideas, I've come up with a couple ideas that I think would be interesting. first is if you're using Base, maybe extending the CDP Agent Kit to integrate with some of our APIs, some of our subgraphs. that could be done by either adding capabilities and integrating
with the LangChain tools—so you can do things like a GraphQL tool and integrate there—or you could also just use LangChain, and you could use the GraphQL chain tool that's available to get some data and define that custom tool that way, or create your own tool with LangChain as well. so those are just a couple of ideas to get you started. you could also run the full stack and maybe index some data, and then do some local AI-related stuff on your local machine, maybe over a database. if you're using Substreams—I didn't get too much into Substreams, but you can go to the Substreams website from StreamingFast, or the introduction to Substreams in the docs. it's a way of doing data processing, it's a little more composable,
and you can output data to a database. so if you want to create your own Substream, store it in a different database, and maybe have your agent talk to that database—that's an option as well. but either way, we're looking for the best use of The Graph inside of an AI agent, so we'll have three different prizes: first, second, and third. we're excited to see what you build. again, if you are just getting started and you need support or anything like that, please, please join the Telegram here, reach out if you have any questions. we're really excited to see what you guys build, and good luck, and we'll see you in the future. thank you [Music]
Related talks
- Full-Stack dApp Development with Scaffold-ETH and The Graph, Day 4
- Amp: Enterprise Grade Blockchain Data that Scales
- Emile Baizel I Building GenAI applications with Amazon Bedrock I Agentic Ethereum 2025
- Building for the Onchain Agent Economy
- Building on The Graph with AI
- The Graph 🛠️ Quickstart to Subgraph Development & Querying - Marcus Rein
- The Graph 🛠 Building decentralized, serverless applications - Ørjan Auestad
- Dune Analytics 🛠 Open Data for Open Finance
- Воркшоп «Блокчейн-аналитика в реальном времени» | Алексей Студнев
