@@ -13,8 +13,12 @@ import { thirdwebClient } from "../../../../shared/utils/sdk";
1313import { getChain } from "../../../../shared/utils/chain" ;
1414import { getChainIdFromChain } from "../../../utils/chain" ;
1515import { getContract , getContractEvents } from "thirdweb" ;
16- import { maybeBigInt } from "../../../../shared/utils/primitive-types" ;
17- import { toContractEventV4Schema } from "../../../schemas/event" ;
16+ import {
17+ type ContractEventV5 ,
18+ toContractEventV4Schema ,
19+ } from "../../../schemas/event" ;
20+ import { createCustomError } from "../../../middleware/error" ;
21+ import { prettifyError } from "../../../../shared/utils/error" ;
1822
1923const requestSchema = contractParamSchema ;
2024
@@ -93,11 +97,21 @@ export async function getAllEvents(fastify: FastifyInstance) {
9397 chain : await getChain ( chainId ) ,
9498 } ) ;
9599
96- const eventsV5 = await getContractEvents ( {
97- contract : contract ,
98- fromBlock : maybeBigInt ( fromBlock ?. toString ( ) ) ,
99- toBlock : maybeBigInt ( toBlock ?. toString ( ) ) ,
100- } ) ;
100+ let eventsV5 : ContractEventV5 [ ] ;
101+ try {
102+ eventsV5 = await getContractEvents ( {
103+ contract : contract ,
104+ fromBlock :
105+ typeof fromBlock === "number" ? BigInt ( fromBlock ) : fromBlock ,
106+ toBlock : typeof toBlock === "number" ? BigInt ( toBlock ) : toBlock ,
107+ } ) ;
108+ } catch ( e ) {
109+ throw createCustomError (
110+ `Failed to get events: ${ prettifyError ( e ) } ` ,
111+ StatusCodes . BAD_REQUEST ,
112+ "BAD_REQUEST" ,
113+ ) ;
114+ }
101115
102116 reply . status ( StatusCodes . OK ) . send ( {
103117 result : eventsV5 . map ( toContractEventV4Schema ) . sort ( ( a , b ) => {
0 commit comments