Skip to content

Commit 0a98c26

Browse files
read contract err
1 parent 7afe2ef commit 0a98c26

File tree

3 files changed

+34
-42
lines changed

3 files changed

+34
-42
lines changed

packages/thirdweb/src/transaction/read-contract.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
prepareMethod,
2626
} from "../utils/abi/prepare-method.js";
2727
import type { Hex } from "../utils/encoding/hex.js";
28+
import { extractError } from "./extract-error.js";
2829

2930
export type ReadContractResult<outputs extends readonly AbiParameter[]> = // if the outputs are 0 length, return never, invalid case
3031
outputs extends { length: 0 }
@@ -211,16 +212,20 @@ export async function readContract<
211212
client: contract.client,
212213
});
213214

214-
const result = await eth_call(rpcRequest, {
215-
data: encodedData,
216-
to: contract.address,
217-
from: options.from,
218-
});
219-
// use the prepared method to decode the result
220-
const decoded = decodeAbiParameters(resolvedPreparedMethod[2], result);
221-
if (Array.isArray(decoded) && decoded.length === 1) {
222-
return decoded[0];
223-
}
215+
try {
216+
const result = await eth_call(rpcRequest, {
217+
data: encodedData,
218+
to: contract.address,
219+
from: options.from,
220+
});
221+
// use the prepared method to decode the result
222+
const decoded = decodeAbiParameters(resolvedPreparedMethod[2], result);
223+
if (Array.isArray(decoded) && decoded.length === 1) {
224+
return decoded[0];
225+
}
224226

225-
return decoded as ReadContractResult<TPreparedMethod[2]>;
227+
return decoded as ReadContractResult<TPreparedMethod[2]>;
228+
} catch (err) {
229+
throw await extractError({ error: err, contract });
230+
}
226231
}

packages/thirdweb/src/wallets/smart/index.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,15 @@ async function createSmartAccount(
312312

313313
const originalMsgHash = hashMessage(message);
314314
// check if the account contract supports EIP721 domain separator or modular based signing
315-
const [messageHash, isModularFactory] = await Promise.all([
315+
const [is712Factory, isModularFactory] = await Promise.all([
316316
readContract({
317317
contract: accountContract,
318318
method:
319319
"function getMessageHash(bytes32 _hash) public view returns (bytes32)",
320320
params: [originalMsgHash],
321-
}).catch((err) => {
322-
console.error(err);
323-
return undefined;
324-
}),
321+
})
322+
.catch(() => false)
323+
.then(() => true),
325324
readContract({
326325
contract: accountContract,
327326
method: "function canInstall(address) public view returns (bool)",
@@ -331,30 +330,15 @@ async function createSmartAccount(
331330
.then(() => true),
332331
]);
333332

334-
console.log("factoryType", messageHash, isModularFactory);
333+
console.log("factoryType", is712Factory, isModularFactory);
335334

336335
let sig: `0x${string}`;
337-
if (messageHash) {
336+
if (is712Factory || isModularFactory) {
338337
const wrappedMessageHash = encodeAbiParameters(
339338
[{ type: "bytes32" }],
340339
[originalMsgHash],
341340
);
342341

343-
const hasheTypedData = hashTypedData({
344-
domain: {
345-
name: isModularFactory ? "DefaultValidator" : "Account",
346-
version: "1",
347-
chainId: options.chain.id,
348-
verifyingContract: accountContract.address,
349-
},
350-
primaryType: "AccountMessage",
351-
types: { AccountMessage: [{ name: "message", type: "bytes" }] },
352-
message: { message: wrappedMessageHash },
353-
});
354-
355-
console.log("hasheTypedData", hasheTypedData);
356-
console.log("equal", messageHash === hasheTypedData);
357-
358342
sig = await options.personalAccount.signTypedData({
359343
domain: {
360344
name: isModularFactory ? "DefaultValidator" : "Account",
@@ -368,13 +352,16 @@ async function createSmartAccount(
368352
});
369353
if (isModularFactory) {
370354
// add validator address
371-
sig = concatHex([ZERO_ADDRESS, sig]);
355+
sig = encodeAbiParameters(
356+
[{ type: "address" }, { type: "bytes" }],
357+
[ZERO_ADDRESS, sig],
358+
);
372359
}
373360
} else {
374361
sig = await options.personalAccount.signMessage({ message });
375362
}
376363

377-
console.log(sig);
364+
console.log("sig", sig);
378365

379366
const isValid = await verifyContractWalletSignature({
380367
address: accountContract.address,

packages/thirdweb/src/wallets/smart/smart-wallet-modular.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { prepareTransaction } from "../../transaction/prepare-transaction.js";
77
import type { Address } from "../../utils/address.js";
88
import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
99
import type { Account, Wallet } from "../interfaces/wallet.js";
10-
import { generateAccount } from "../utils/generateAccount.js";
1110
import { smartWallet } from "./smart-wallet.js";
12-
11+
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
1312
let wallet: Wallet;
1413
let smartAccount: Account;
1514
let smartWalletAddress: Address;
@@ -28,9 +27,10 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
2827
},
2928
() => {
3029
beforeAll(async () => {
31-
personalAccount = await generateAccount({
32-
client,
33-
});
30+
personalAccount = TEST_ACCOUNT_A;
31+
// personalAccount = await generateAccount({
32+
// client,
33+
// });
3434
wallet = smartWallet({
3535
chain,
3636
gasless: true,
@@ -52,9 +52,9 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
5252
expect(smartWalletAddress).toHaveLength(42);
5353

5454
// const d = decodeErrorResult({
55-
// data: "0x79bd117bb61d27f600000000000000000000000000000000000000000000000000000000",
55+
// data: "0xb927fe5e0000000000000000000000000000000000000000db72e07d8a92f3d9d30e3843",
5656
// abi: await resolveContractAbi({
57-
// address: ENTRYPOINT_ADDRESS_v0_7,
57+
// address: smartWalletAddress,
5858
// client,
5959
// chain,
6060
// }),

0 commit comments

Comments
 (0)