Any accessible Contract exposed by the SDK exposes 2 public methods to help retrieve typed event information.
getLogsExample.ts
Copy
Ask AI
import { BoostCore, BoostCoreLog } from '@boostxyz/sdk'// instantiate a protocol contractconst core = new BoostCore({ config })// you can import typed log types for your own utilityconst anyLogs: BoostCoreLog[]const boostCreatedLogs: BoostCoreLog<'BoostCreated'>[]boostCreatedLogs = await core.getLogs({ // If you provide a specific event name, the returned log type will have typesafe values eventName: 'BoostCreated' // you can also pass an array of event names eventNames: ['BoostCreated'], // you can pass any parameters you would give to https://viem.sh/docs/actions/public/getLogs#getlogs fromBlock: 16330000n, toBlock: 16330050n})
subscribeExample.ts
Copy
Ask AI
import { BoostCore, BoostCoreLog } from '@boostxyz/sdk'// instantiate a protocol contractconst core = new BoostCore({ config })// you can import typed log types for your own utilityconst anyLogs: BoostCoreLog[]const boostCreatedLogs: BoostCoreLog<'BoostCreated'>[]// if you provide an eventName to listen to, you don't need to explicitly type the callback, this is just a referenceconst unsubscribe = core.subscribe( (log: BoostCoreLog<'BoostCreated'>) => { boostCreatedLogs.push(log) }, { eventName: 'BoostCreated', // you can pass any parameters you would give to https://wagmi.sh/core/api/actions/watchContractEvent#watchcontractevent batch: true, chainId: 31337, onError: (e: Error) => {}, poll: false, pollingInterval: 1000, strict: true, syncConnectedChain: false, })// call unsubscribe to clean up your listenerunsubscribe()