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/slow-mice-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Add retry logic to predictAccountAddress
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
const condition = await getClaimConditions({
contract,
tokenId: 0n,
singlePhaseDrop: true,
});
expect(condition.length).to.eq(1);
expect(condition[0]?.maxClaimableSupply).to.eq(10n);
Expand Down
34 changes: 29 additions & 5 deletions packages/thirdweb/src/wallets/smart/lib/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,35 @@
accountSalt && isHex(accountSalt)
? accountSalt
: stringToHex(accountSalt ?? "");
return readContract({
contract: factoryContract,
method: "function getAddress(address, bytes) returns (address)",
params: [adminAddress, saltHex],
});
let result: string | undefined;
let retries = 0;
const maxRetries = 3;

while (retries <= maxRetries) {
try {
result = await readContract({
contract: factoryContract,
method: "function getAddress(address, bytes) returns (address)",
params: [adminAddress, saltHex],
});
break;
} catch (error) {
if (retries === maxRetries) {
throw error;
}

Check warning on line 115 in packages/thirdweb/src/wallets/smart/lib/calls.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/smart/lib/calls.ts#L113-L115

Added lines #L113 - L115 were not covered by tests

// Exponential backoff: 2^(retries + 1) * 100ms (200ms, 400ms, 800ms)
const delay = 2 ** (retries + 1) * 100;
await new Promise((resolve) => setTimeout(resolve, delay));
retries++;
}

Check warning on line 121 in packages/thirdweb/src/wallets/smart/lib/calls.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/smart/lib/calls.ts#L118-L121

Added lines #L118 - L121 were not covered by tests
}
if (!result) {
throw new Error(
`No smart account address found for admin address ${adminAddress} and salt ${accountSalt}`,
);
}

Check warning on line 127 in packages/thirdweb/src/wallets/smart/lib/calls.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/smart/lib/calls.ts#L124-L127

Added lines #L124 - L127 were not covered by tests
return result;
},
{
cacheKey: `${args.factoryContract.chain.id}-${args.factoryContract.address}-${args.adminAddress}-${args.accountSalt}`,
Expand Down