Skip to content

Commit 720f290

Browse files
committed
fix(sdk): smart account transactions on non-original chain
1 parent 7846be4 commit 720f290

File tree

1 file changed

+16
-15
lines changed
  • packages/thirdweb/src/wallets/smart

1 file changed

+16
-15
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ async function createSmartAccount(
214214
}
215215
}
216216

217-
const { accountContract } = options;
217+
let accountContract = options.accountContract;
218218
const account: Account = {
219219
address: getAddress(accountContract.address),
220220
async sendTransaction(transaction: SendTransactionOption) {
@@ -241,21 +241,17 @@ async function createSmartAccount(
241241
paymasterOverride = options.overrides?.paymaster;
242242
}
243243

244-
const accountContractForTransaction = (() => {
245-
// If this transaction is for a different chain than the initial one, get the account contract for that chain
246-
if (transaction.chainId !== accountContract.chain.id) {
247-
return getContract({
248-
address: account.address,
249-
chain: getCachedChain(transaction.chainId),
250-
client: options.client,
251-
});
252-
}
253-
// Default to the existing account contract
254-
return accountContract;
255-
})();
244+
// If this transaction is for a different chain than the initial one, get the account contract for that chain
245+
if (transaction.chainId !== accountContract.chain.id) {
246+
accountContract = getContract({
247+
address: account.address,
248+
chain: getCachedChain(transaction.chainId),
249+
client: options.client,
250+
});
251+
}
256252

257253
const executeTx = prepareExecute({
258-
accountContract: accountContractForTransaction,
254+
accountContract: accountContract,
259255
transaction,
260256
executeOverride: options.overrides?.execute,
261257
});
@@ -264,6 +260,7 @@ async function createSmartAccount(
264260
options: {
265261
...options,
266262
chain: getCachedChain(transaction.chainId),
263+
accountContract,
267264
overrides: {
268265
...options.overrides,
269266
paymaster: paymasterOverride,
@@ -279,7 +276,11 @@ async function createSmartAccount(
279276
});
280277
return _sendUserOp({
281278
executeTx,
282-
options,
279+
options: {
280+
...options,
281+
chain: getCachedChain(transactions[0]?.chainId ?? options.chain.id),
282+
accountContract,
283+
},
283284
});
284285
},
285286
async signMessage({ message }: { message: SignableMessage }) {

0 commit comments

Comments
 (0)