@@ -11,6 +11,8 @@ import { getRpcUrlForChain } from "../chains/utils.js";
11
11
import type { Chain } from "../chains/types.js" ;
12
12
import { getContract , type ThirdwebContract } from "../contract/contract.js" ;
13
13
import { toHex , uint8ArrayToHex } from "../utils/encoding/hex.js" ;
14
+ import { toSerializableTransaction } from "../transaction/actions/to-serializable-transaction.js" ;
15
+ import type { PreparedTransaction } from "../transaction/prepare-transaction.js" ;
14
16
15
17
type Ethers6 = typeof ethers6 ;
16
18
@@ -305,25 +307,30 @@ async function toEthersSigner(
305
307
}
306
308
// eslint-disable-next-line jsdoc/require-jsdoc
307
309
override async sendTransaction (
308
- tx : ethers6 . ethers . TransactionRequest & { chainId : number } ,
310
+ tx : ethers6 . ethers . TransactionRequest ,
309
311
) : Promise < ethers6 . ethers . TransactionResponse > {
310
- const alignedTx = await alignTxFromEthers ( tx ) ;
311
312
if ( ! account ) {
312
313
throw new Error ( "Account not found" ) ;
313
314
}
314
- const result = await account . sendTransaction ( {
315
- ...alignedTx ,
316
- chainId : tx . chainId ,
315
+ const ethersTx = await alignTxFromEthers ( {
316
+ chain,
317
+ client,
318
+ tx,
319
+ } ) ;
320
+ const serializableTx = await toSerializableTransaction ( {
321
+ transaction : ethersTx ,
322
+ from : account . address ,
317
323
} ) ;
324
+ const result = await account . sendTransaction ( serializableTx ) ;
318
325
319
326
const txResponseParams : ethers6 . TransactionResponseParams = {
320
- ...alignedTx ,
327
+ ...serializableTx ,
321
328
blockHash : null ,
322
329
from : this . address ,
323
330
hash : result . transactionHash as string ,
324
331
blockNumber : null ,
325
332
index : 0 ,
326
- gasLimit : alignedTx . gas as bigint ,
333
+ gasLimit : serializableTx . gas as bigint ,
327
334
// @ts -expect-error - we don't have this reliably so we'll just not include it
328
335
signature : null ,
329
336
} ;
@@ -340,9 +347,16 @@ async function toEthersSigner(
340
347
if ( ! account . signTransaction ) {
341
348
throw new Error ( "Account does not support signing transactions" ) ;
342
349
}
343
- const viemTx = await alignTxFromEthers ( tx ) ;
344
-
345
- return account . signTransaction ( viemTx ) ;
350
+ const ethersTx = await alignTxFromEthers ( {
351
+ chain,
352
+ client,
353
+ tx,
354
+ } ) ;
355
+ const serializableTx = await toSerializableTransaction ( {
356
+ transaction : ethersTx ,
357
+ from : account . address ,
358
+ } ) ;
359
+ return account . signTransaction ( serializableTx ) ;
346
360
}
347
361
// eslint-disable-next-line jsdoc/require-jsdoc
348
362
override signMessage ( message : string | Uint8Array ) : Promise < string > {
@@ -423,9 +437,12 @@ function alignTxToEthers(
423
437
return { ...rest , type } ;
424
438
}
425
439
426
- async function alignTxFromEthers (
427
- tx : ethers6 . TransactionRequest ,
428
- ) : Promise < TransactionSerializable > {
440
+ async function alignTxFromEthers ( options : {
441
+ client : ThirdwebClient ;
442
+ chain : Chain ;
443
+ tx : ethers6 . TransactionRequest ;
444
+ } ) : Promise < PreparedTransaction > {
445
+ const { client, chain, tx } = options ;
429
446
const {
430
447
type : ethersType ,
431
448
accessList,
@@ -453,11 +470,10 @@ async function alignTxFromEthers(
453
470
throw new Error ( "ChainId is required for EIP-2930 transactions" ) ;
454
471
}
455
472
return {
456
- type : "eip2930" ,
457
-
458
- chainId,
473
+ client,
474
+ chain,
459
475
accessList : accessList as AccessList ,
460
- to,
476
+ to : ( to ?? undefined ) as string | undefined ,
461
477
data : ( data ?? undefined ) as Hex | undefined ,
462
478
gasPrice : gasPrice ? bigNumberIshToBigint ( gasPrice ) : undefined ,
463
479
gas : gasLimit ? bigNumberIshToBigint ( gasLimit ) : undefined ,
@@ -470,10 +486,10 @@ async function alignTxFromEthers(
470
486
throw new Error ( "ChainId is required for EIP-1559 transactions" ) ;
471
487
}
472
488
return {
473
- type : "eip1559" ,
474
- chainId ,
489
+ client ,
490
+ chain ,
475
491
accessList : accessList as AccessList ,
476
- to,
492
+ to : ( to ?? undefined ) as string | undefined ,
477
493
data : ( data ?? undefined ) as Hex | undefined ,
478
494
gas : gasLimit ? bigNumberIshToBigint ( gasLimit ) : undefined ,
479
495
nonce : nonce ?? undefined ,
@@ -490,9 +506,9 @@ async function alignTxFromEthers(
490
506
default : {
491
507
// fall back to legacy
492
508
return {
493
- type : "legacy" ,
494
- chainId ,
495
- to,
509
+ client ,
510
+ chain ,
511
+ to : ( to ?? undefined ) as string | undefined ,
496
512
data : ( data ?? undefined ) as Hex | undefined ,
497
513
nonce : nonce ?? undefined ,
498
514
value : value ? bigNumberIshToBigint ( value ) : undefined ,
0 commit comments