How to call read-only function from other contract address inside the event handler? #179
-
Hey. I'm trying to rewrite the univ2 subgraph with ponder for learning purpose, and currently I'm stuck with how to get the token metadata (name, symbol, etc). AFAIK we can't define Contract object without address in ponder, hence I cannot call Given contract address inside the event handler, what is the ponder-way to execute a read-only function of the given address? I'm trying to use Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for the question! A few points here:
ponder.on("ContractName:EventName", async ({ event, context }) => {
const client = context.networks.mainnet.client // viem.PublicClient object
const response = await client.readContract( /* ... */)
// ...
}); The problem with exposing this is that there are some footguns. The Will continue to think on this - appreciate any ideas! |
Beta Was this translation helpful? Give feedback.
Thanks for the question! A few points here:
context.contracts
object currently includes aReadOnlyContract
object for each contract defined inponder.config.ts
. This has proven convenient for a lot of projects, but it's not as powerful as just having theviem.PublicClient
object for each network. There's nothing stopping us from including those. It could look like this: