@@ -14,7 +14,12 @@ import { getChain } from "../../../../shared/utils/chain";
1414import { getChainIdFromChain } from "../../../utils/chain" ;
1515import { getContract , getContractEvents } from "thirdweb" ;
1616import { maybeBigInt } from "../../../../shared/utils/primitive-types" ;
17- import { toContractEventV4Schema } from "../../../schemas/event" ;
17+ import {
18+ ContractEventV5 ,
19+ toContractEventV4Schema ,
20+ } from "../../../schemas/event" ;
21+ import { createCustomError } from "../../../middleware/error" ;
22+ import { prettifyError } from "../../../../shared/utils/error" ;
1823
1924const requestSchema = contractParamSchema ;
2025
@@ -93,11 +98,21 @@ export async function getAllEvents(fastify: FastifyInstance) {
9398 chain : await getChain ( chainId ) ,
9499 } ) ;
95100
96- const eventsV5 = await getContractEvents ( {
97- contract : contract ,
98- fromBlock : maybeBigInt ( fromBlock ?. toString ( ) ) ,
99- toBlock : maybeBigInt ( toBlock ?. toString ( ) ) ,
100- } ) ;
101+ let eventsV5 : ContractEventV5 [ ] ;
102+ try {
103+ eventsV5 = await getContractEvents ( {
104+ contract : contract ,
105+ fromBlock :
106+ typeof fromBlock === "number" ? BigInt ( fromBlock ) : fromBlock ,
107+ toBlock : typeof toBlock === "number" ? BigInt ( toBlock ) : toBlock ,
108+ } ) ;
109+ } catch ( e ) {
110+ throw createCustomError (
111+ `Failed to get events: ${ prettifyError ( e ) } ` ,
112+ StatusCodes . BAD_REQUEST ,
113+ "BAD_REQUEST" ,
114+ ) ;
115+ }
101116
102117 reply . status ( StatusCodes . OK ) . send ( {
103118 result : eventsV5 . map ( toContractEventV4Schema ) . sort ( ( a , b ) => {
0 commit comments