@@ -3,21 +3,21 @@ import type { FastifyInstance } from "fastify";
33import { StatusCodes } from "http-status-codes" ;
44import SuperJSON from "superjson" ;
55import {
6+ encode ,
67 getContract ,
78 prepareContractCall ,
89 readContract ,
910 resolveMethod ,
1011} from "thirdweb" ;
1112import { prepareMethod } from "thirdweb/contract" ;
12- import { resolvePromisedValue , type AbiFunction } from "thirdweb/utils" ;
1313import { decodeAbiParameters } from "viem/utils" ;
14- import { getChain } from "../../../../utils/chain" ;
15- import { prettifyError } from "../../../../utils/error" ;
16- import { thirdwebClient } from "../../../../utils/sdk" ;
14+ import type { AbiFunction } from "viem" ;
1715import { createCustomError } from "../../../middleware/error" ;
18- import { standardResponseSchema } from "../../../schemas/sharedApiSchemas" ;
1916import { getChainIdFromChain } from "../../../utils/chain" ;
20- import { bigNumberReplacer } from "../../../utils/convertor" ;
17+ import { standardResponseSchema } from "../../../schemas/shared-api-schemas" ;
18+ import { getChain } from "../../../../shared/utils/chain" ;
19+ import { thirdwebClient } from "../../../../shared/utils/sdk" ;
20+ import { prettifyError } from "../../../../shared/utils/error" ;
2121
2222const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11" ;
2323
@@ -33,7 +33,11 @@ const readCallRequestItemSchema = Type.Object({
3333
3434const readMulticallRequestSchema = Type . Object ( {
3535 calls : Type . Array ( readCallRequestItemSchema ) ,
36- multicallAddress : Type . Optional ( Type . String ( ) ) ,
36+ multicallAddress : Type . Optional (
37+ Type . String ( {
38+ description : `Address of the multicall contract to use. If omitted, multicall3 contract will be used (${ MULTICALL3_ADDRESS } ).` ,
39+ } ) ,
40+ ) ,
3741} ) ;
3842
3943const responseSchema = Type . Object ( {
@@ -55,16 +59,16 @@ type RouteGeneric = {
5559 Reply : Static < typeof responseSchema > ;
5660} ;
5761
58- export async function readMulticall ( fastify : FastifyInstance ) {
62+ export async function readMulticallRoute ( fastify : FastifyInstance ) {
5963 fastify . route < RouteGeneric > ( {
6064 method : "POST" ,
6165 url : "/contract/:chain/read-batch" ,
6266 schema : {
6367 summary : "Batch read from multiple contracts" ,
6468 description :
65- "Execute multiple contract read operations in a single call using Multicall3 " ,
69+ "Execute multiple contract read operations in a single call using Multicall " ,
6670 tags : [ "Contract" ] ,
67- operationId : "readMulticall " ,
71+ operationId : "readBatch " ,
6872 params : paramsSchema ,
6973 body : readMulticallRequestSchema ,
7074 response : {
@@ -83,7 +87,7 @@ export async function readMulticall(fastify: FastifyInstance) {
8387 // Encode each read call
8488 const encodedCalls = await Promise . all (
8589 calls . map ( async ( call ) => {
86- const contract = await getContract ( {
90+ const contract = getContract ( {
8791 client : thirdwebClient ,
8892 chain,
8993 address : call . contractAddress ,
@@ -97,13 +101,9 @@ export async function readMulticall(fastify: FastifyInstance) {
97101 contract,
98102 method,
99103 params : call . args || [ ] ,
100- // stubbing gas values so that the call can be encoded
101- maxFeePerGas : 30n ,
102- maxPriorityFeePerGas : 1n ,
103- value : 0n ,
104104 } ) ;
105105
106- const calldata = await resolvePromisedValue ( transaction . data ) ;
106+ const calldata = await encode ( transaction ) ;
107107 if ( ! calldata ) {
108108 throw new Error ( "Failed to encode call data" ) ;
109109 }
@@ -149,7 +149,7 @@ export async function readMulticall(fastify: FastifyInstance) {
149149
150150 return {
151151 success,
152- result : success ? bigNumberReplacer ( decoded ) : null ,
152+ result : success ? decoded : null ,
153153 } ;
154154 } ) ;
155155
0 commit comments