Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-walls-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Ensure smart accounts are deployed before validating signatures
31 changes: 31 additions & 0 deletions packages/thirdweb/src/wallets/smart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@
account,
accountContract,
});
// the bundler and rpc might not be in sync, so while the bundler has a transaction hash for the deployment,
// the rpc might not have it yet, so we wait until the rpc confirms the contract is deployed
await confirmContractDeployment({
accountContract,
});
}

const originalMsgHash = hashMessage(message);
Expand Down Expand Up @@ -344,6 +349,11 @@
account,
accountContract,
});
// the bundler and rpc might not be in sync, so while the bundler has a transaction hash for the deployment,
// the rpc might not have it yet, so we wait until the rpc confirms the contract is deployed
await confirmContractDeployment({
accountContract,
});

Check warning on line 356 in packages/thirdweb/src/wallets/smart/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/smart/index.ts#L354-L356

Added lines #L354 - L356 were not covered by tests
}

const originalMsgHash = hashTypedData(typedData);
Expand Down Expand Up @@ -607,3 +617,24 @@
transactionHash: receipt.transactionHash,
};
}

async function confirmContractDeployment(args: {
accountContract: ThirdwebContract;
}) {
const { accountContract } = args;
const startTime = Date.now();
const timeout = 60000; // wait 1 minute max
const { isContractDeployed } = await import(
"../../utils/bytecode/is-contract-deployed.js"
);
let isDeployed = await isContractDeployed(accountContract);
while (!isDeployed) {
if (Date.now() - startTime > timeout) {
throw new Error(
"Timeout: Smart account deployment not confirmed after 1 minute",
);
}
await new Promise((resolve) => setTimeout(resolve, 500));
isDeployed = await isContractDeployed(accountContract);
}

Check warning on line 639 in packages/thirdweb/src/wallets/smart/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/smart/index.ts#L632-L639

Added lines #L632 - L639 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { beforeAll, describe, expect, it } from "vitest";
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum-sepolia.js";
import { type ThirdwebContract, getContract } from "../../contract/contract.js";

import { balanceOf } from "../../extensions/erc1155/__generated__/IERC1155/read/balanceOf.js";
import { claimTo } from "../../extensions/erc1155/drops/write/claimTo.js";
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
Expand Down Expand Up @@ -62,6 +61,12 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
expect(smartWalletAddress).toHaveLength(42);
});

it("can sign a msg", async () => {
await smartAccount.signMessage({ message: "hello world" });
const isDeployed = await isContractDeployed(accountContract);
expect(isDeployed).toEqual(true);
});

it("can execute a tx", async () => {
const tx = await sendAndConfirmTransaction({
transaction: claimTo({
Expand Down