@@ -7,9 +7,9 @@ import type { Chain } from "../chains/types.js";
7
7
import { getRpcUrlForChain } from "../chains/utils.js" ;
8
8
import type { ThirdwebClient } from "../client/client.js" ;
9
9
import { type ThirdwebContract , getContract } from "../contract/contract.js" ;
10
- import { sendTransaction } from "../transaction/actions/send -transaction.js" ;
10
+ import { toSerializableTransaction } from "../transaction/actions/to-serializable -transaction.js" ;
11
11
import { waitForReceipt } from "../transaction/actions/wait-for-tx-receipt.js" ;
12
- import { prepareTransaction } from "../transaction/prepare-transaction.js" ;
12
+ import type { PreparedTransaction } from "../transaction/prepare-transaction.js" ;
13
13
import { toHex } from "../utils/encoding/hex.js" ;
14
14
import type { Account } from "../wallets/interfaces/wallet.js" ;
15
15
@@ -322,9 +322,17 @@ export async function toEthersSigner(
322
322
throw new Error ( "Account does not support signTransaction" ) ;
323
323
}
324
324
const awaitedTx = await ethers . utils . resolveProperties ( transaction ) ;
325
- return account . signTransaction (
326
- await alignTxFromEthers ( awaitedTx , ethers ) ,
325
+ const alignedTx = await alignTxFromEthers (
326
+ client ,
327
+ chain ,
328
+ awaitedTx ,
329
+ ethers ,
327
330
) ;
331
+ const serialized = await toSerializableTransaction ( {
332
+ transaction : alignedTx ,
333
+ from : account . address ,
334
+ } ) ;
335
+ return account . signTransaction ( serialized ) ;
328
336
}
329
337
330
338
/**
@@ -340,33 +348,43 @@ export async function toEthersSigner(
340
348
throw new Error ( "Account does not support sendTransaction" ) ;
341
349
}
342
350
const awaitedTx = await ethers . utils . resolveProperties ( transaction ) ;
343
- const alignedTx = await alignTxFromEthers ( awaitedTx , ethers ) ;
344
- const tx = prepareTransaction ( {
345
- client : client ,
346
- chain : chain ,
347
- accessList : alignedTx . accessList ,
348
- data : alignedTx . data ,
349
- nonce : alignedTx . nonce ,
350
- to : alignedTx . to ?? undefined ,
351
- value : alignedTx . value ,
352
- } ) ;
353
- const result = await sendTransaction ( {
354
- transaction : tx ,
355
- account : account ,
351
+ const alignedTx = await alignTxFromEthers (
352
+ client ,
353
+ chain ,
354
+ awaitedTx ,
355
+ ethers ,
356
+ ) ;
357
+ const serialized = await toSerializableTransaction ( {
358
+ transaction : alignedTx ,
359
+ from : account . address ,
356
360
} ) ;
361
+ const result = await account . sendTransaction ( serialized ) ;
357
362
358
363
const response : ethers5 . ethers . providers . TransactionResponse = {
359
- chainId : tx . chain . id ,
364
+ ...serialized ,
365
+ nonce : serialized . nonce ?? 0 ,
360
366
from : account . address ,
361
- data : alignedTx . data ?? "0x" ,
362
- nonce : alignedTx . nonce ?? 0 ,
367
+ maxFeePerGas : serialized . maxFeePerGas
368
+ ? ethers . BigNumber . from ( serialized . maxFeePerGas )
369
+ : undefined ,
370
+ maxPriorityFeePerGas : serialized . maxPriorityFeePerGas
371
+ ? ethers . BigNumber . from ( serialized . maxPriorityFeePerGas )
372
+ : undefined ,
373
+ gasPrice : serialized . gasPrice
374
+ ? ethers . BigNumber . from ( serialized . gasPrice )
375
+ : undefined ,
376
+ accessList : serialized . accessList as ethers5 . ethers . utils . AccessList ,
363
377
value : ethers . BigNumber . from ( alignedTx . value ?? 0 ) ,
364
378
gasLimit : ethers . BigNumber . from ( alignedTx . gas ?? 0 ) ,
365
379
// biome-ignore lint/style/noNonNullAssertion: TODO: fix later
366
380
hash : result . transactionHash ! ,
367
381
confirmations : 0 ,
368
382
wait : async ( ) => {
369
- const receipt = await waitForReceipt ( result ) ;
383
+ const receipt = await waitForReceipt ( {
384
+ transactionHash : result . transactionHash ,
385
+ chain,
386
+ client,
387
+ } ) ;
370
388
return {
371
389
...receipt ,
372
390
type :
@@ -491,9 +509,11 @@ function alignTxToEthers(
491
509
}
492
510
493
511
async function alignTxFromEthers (
512
+ client : ThirdwebClient ,
513
+ chain : Chain ,
494
514
tx : ethers5 . ethers . providers . TransactionRequest ,
495
515
ethers : Ethers5 ,
496
- ) : Promise < TransactionSerializable > {
516
+ ) : Promise < PreparedTransaction > {
497
517
const {
498
518
type : ethersType ,
499
519
accessList,
@@ -514,8 +534,8 @@ async function alignTxFromEthers(
514
534
throw new Error ( "ChainId is required for EIP-2930 transactions" ) ;
515
535
}
516
536
return {
517
- type : "eip2930" ,
518
- chainId ,
537
+ client ,
538
+ chain ,
519
539
to,
520
540
data : ( data ?? undefined ) as Hex | undefined ,
521
541
nonce : nonce ? ethers . BigNumber . from ( nonce ) . toNumber ( ) : undefined ,
@@ -532,8 +552,8 @@ async function alignTxFromEthers(
532
552
throw new Error ( "ChainId is required for EIP-1559 transactions" ) ;
533
553
}
534
554
return {
535
- type : "eip1559" ,
536
- chainId ,
555
+ client ,
556
+ chain ,
537
557
to,
538
558
data : ( data ?? undefined ) as Hex | undefined ,
539
559
nonce : nonce ? ethers . BigNumber . from ( nonce ) . toNumber ( ) : undefined ,
@@ -549,8 +569,8 @@ async function alignTxFromEthers(
549
569
}
550
570
default : {
551
571
return {
552
- type : "legacy" ,
553
- chainId ,
572
+ client ,
573
+ chain ,
554
574
to,
555
575
data : ( data ?? undefined ) as Hex | undefined ,
556
576
nonce : nonce ? ethers . BigNumber . from ( nonce ) . toNumber ( ) : undefined ,
0 commit comments