@@ -3,21 +3,21 @@ import type { FastifyInstance } from "fastify";
3
3
import { StatusCodes } from "http-status-codes" ;
4
4
import SuperJSON from "superjson" ;
5
5
import {
6
+ encode ,
6
7
getContract ,
7
8
prepareContractCall ,
8
9
readContract ,
9
10
resolveMethod ,
10
11
} from "thirdweb" ;
11
12
import { prepareMethod } from "thirdweb/contract" ;
12
- import { resolvePromisedValue , type AbiFunction } from "thirdweb/utils" ;
13
13
import { 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" ;
17
15
import { createCustomError } from "../../../middleware/error" ;
18
- import { standardResponseSchema } from "../../../schemas/sharedApiSchemas" ;
19
16
import { 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" ;
21
21
22
22
const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11" ;
23
23
@@ -33,7 +33,11 @@ const readCallRequestItemSchema = Type.Object({
33
33
34
34
const readMulticallRequestSchema = Type . Object ( {
35
35
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
+ ) ,
37
41
} ) ;
38
42
39
43
const responseSchema = Type . Object ( {
@@ -55,16 +59,16 @@ type RouteGeneric = {
55
59
Reply : Static < typeof responseSchema > ;
56
60
} ;
57
61
58
- export async function readMulticall ( fastify : FastifyInstance ) {
62
+ export async function readMulticallRoute ( fastify : FastifyInstance ) {
59
63
fastify . route < RouteGeneric > ( {
60
64
method : "POST" ,
61
65
url : "/contract/:chain/read-batch" ,
62
66
schema : {
63
67
summary : "Batch read from multiple contracts" ,
64
68
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 " ,
66
70
tags : [ "Contract" ] ,
67
- operationId : "readMulticall " ,
71
+ operationId : "readBatch " ,
68
72
params : paramsSchema ,
69
73
body : readMulticallRequestSchema ,
70
74
response : {
@@ -83,7 +87,7 @@ export async function readMulticall(fastify: FastifyInstance) {
83
87
// Encode each read call
84
88
const encodedCalls = await Promise . all (
85
89
calls . map ( async ( call ) => {
86
- const contract = await getContract ( {
90
+ const contract = getContract ( {
87
91
client : thirdwebClient ,
88
92
chain,
89
93
address : call . contractAddress ,
@@ -97,13 +101,9 @@ export async function readMulticall(fastify: FastifyInstance) {
97
101
contract,
98
102
method,
99
103
params : call . args || [ ] ,
100
- // stubbing gas values so that the call can be encoded
101
- maxFeePerGas : 30n ,
102
- maxPriorityFeePerGas : 1n ,
103
- value : 0n ,
104
104
} ) ;
105
105
106
- const calldata = await resolvePromisedValue ( transaction . data ) ;
106
+ const calldata = await encode ( transaction ) ;
107
107
if ( ! calldata ) {
108
108
throw new Error ( "Failed to encode call data" ) ;
109
109
}
@@ -149,7 +149,7 @@ export async function readMulticall(fastify: FastifyInstance) {
149
149
150
150
return {
151
151
success,
152
- result : success ? bigNumberReplacer ( decoded ) : null ,
152
+ result : success ? decoded : null ,
153
153
} ;
154
154
} ) ;
155
155
0 commit comments