Skip to content

Commit c327871

Browse files
Add support for untyped contract args in /write
1 parent 844d297 commit c327871

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

src/server/routes/contract/write/write.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Type, type Static } from "@sinclair/typebox";
1+
import { type Static, Type } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { prepareContractCall, resolveMethod } from "thirdweb";
5-
import type { AbiFunction } from "thirdweb/utils";
5+
import { type AbiFunction, parseAbiParams } from "thirdweb/utils";
66
import { getContractV5 } from "../../../../utils/cache/getContractv5";
77
import { prettifyError } from "../../../../utils/error";
88
import { queueTransaction } from "../../../../utils/transaction/queueTransation";
@@ -92,10 +92,14 @@ export async function writeToContract(fastify: FastifyInstance) {
9292
"BAD_REQUEST",
9393
);
9494
}
95+
const params = parseAbiParams(
96+
method.inputs.map((i) => i.type),
97+
args,
98+
);
9599
const transaction = prepareContractCall({
96100
contract,
97101
method,
98-
params: args,
102+
params,
99103
...parseTransactionOverrides(txOverrides),
100104
});
101105

test/e2e/tests/write.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,63 @@ describe("Write Tests", () => {
6969
expect(writeTransactionStatus.minedAt).toBeDefined();
7070
});
7171

72+
test.only("Write to a contract with untyped args", async () => {
73+
const res = await engine.deploy.deployNftDrop(
74+
CONFIG.CHAIN.id.toString(),
75+
backendWallet,
76+
{
77+
contractMetadata: {
78+
name: "test token",
79+
platform_fee_basis_points: 0,
80+
platform_fee_recipient: zeroAddress,
81+
symbol: "TT",
82+
trusted_forwarders: [],
83+
seller_fee_basis_points: 0,
84+
fee_recipient: zeroAddress,
85+
},
86+
},
87+
);
88+
89+
expect(res.result.queueId).toBeDefined();
90+
assert(res.result.queueId, "queueId must be defined");
91+
expect(res.result.deployedAddress).toBeDefined();
92+
const nftDropContractAddress = res.result.deployedAddress;
93+
94+
if (!nftDropContractAddress) {
95+
throw new Error("nftDropContractAddress must be defined");
96+
}
97+
98+
const transactionStatus = await pollTransactionStatus(
99+
engine,
100+
res.result.queueId,
101+
true,
102+
);
103+
104+
expect(transactionStatus.minedAt).toBeDefined();
105+
const writeRes = await engine.contract.write(
106+
CONFIG.CHAIN.id.toString(),
107+
nftDropContractAddress,
108+
backendWallet,
109+
{
110+
functionName: "setApprovalForAll",
111+
args: [
112+
"0x1234567890123456789012345678901234567890",
113+
"true", // string instead of bool
114+
],
115+
},
116+
);
117+
118+
expect(writeRes.result.queueId).toBeDefined();
119+
120+
const writeTransactionStatus = await pollTransactionStatus(
121+
engine,
122+
writeRes.result.queueId,
123+
true,
124+
);
125+
126+
expect(writeTransactionStatus.minedAt).toBeDefined();
127+
});
128+
72129
test("Write to a contract with function signature", async () => {
73130
const writeRes = await engine.contract.write(
74131
CONFIG.CHAIN.id.toString(),

0 commit comments

Comments
 (0)