@@ -5,6 +5,8 @@ import type { Prettify } from "../../utils/type-utils.js";
55import type { Account } from "../../wallets/interfaces/wallet.js" ;
66import { extractError } from "../extract-error.js" ;
77import type { PreparedTransaction } from "../prepare-transaction.js" ;
8+ import { resolveAndSignAuthorizations } from "./to-serializable-transaction.js" ;
9+ import * as ox__Hex from "ox/Hex" ;
810
911export type EstimateGasOptions = Prettify <
1012 {
@@ -16,19 +18,21 @@ export type EstimateGasOptions = Prettify<
1618 transaction : PreparedTransaction < any > ;
1719 } & (
1820 | {
19- /**
20- * The account the transaction would be sent from.
21- */
22- account : Account ;
23- from ?: never ;
24- }
21+ /**
22+ * The account the transaction would be sent from.
23+ *
24+ * @deprecated Use `from` instead
25+ */
26+ account : Account ;
27+ from ?: never ;
28+ }
2529 | {
26- account ?: never ;
27- /**
28- * The address the transaction would be sent from.
29- */
30- from ?: string ;
31- }
30+ account ?: never ;
31+ /**
32+ * The address the transaction would be sent from.
33+ */
34+ from ?: string | Account ;
35+ }
3236 )
3337> ;
3438
@@ -60,8 +64,11 @@ export async function estimateGas(
6064 // 1. the user specified from address
6165 // 2. the passed in account address
6266 // 3. the passed in wallet's account address
63- const from = options . from ?? options . account ?. address ?? undefined ;
64- const txWithFrom = { ...options . transaction , from } ;
67+ const fromAddress =
68+ typeof options . from === "string"
69+ ? options . from ?? undefined
70+ : options . from ?. address ?? options . account ?. address ;
71+ const txWithFrom = { ...options . transaction , from : fromAddress } ;
6572 if ( cache . has ( txWithFrom ) ) {
6673 // biome-ignore lint/style/noNonNullAssertion: the `has` above ensures that this will always be set
6774 return cache . get ( txWithFrom ) ! ;
@@ -92,11 +99,13 @@ export async function estimateGas(
9299
93100 // load up encode function if we need it
94101 const { encode } = await import ( "./encode.js" ) ;
95- const [ encodedData , toAddress , value ] = await Promise . all ( [
96- encode ( options . transaction ) ,
97- resolvePromisedValue ( options . transaction . to ) ,
98- resolvePromisedValue ( options . transaction . value ) ,
99- ] ) ;
102+ const [ encodedData , toAddress , value , authorizationList ] =
103+ await Promise . all ( [
104+ encode ( options . transaction ) ,
105+ resolvePromisedValue ( options . transaction . to ) ,
106+ resolvePromisedValue ( options . transaction . value ) ,
107+ resolveAndSignAuthorizations ( options ) ,
108+ ] ) ;
100109
101110 // load up the rpc client and the estimateGas function if we need it
102111 const [ { getRpcClient } , { eth_estimateGas } ] = await Promise . all ( [
@@ -111,8 +120,16 @@ export async function estimateGas(
111120 formatTransactionRequest ( {
112121 to : toAddress ,
113122 data : encodedData ,
114- from,
123+ from : fromAddress ,
115124 value,
125+ // TODO: Remove this casting when we migrate this file to Ox
126+ authorizationList : authorizationList ?. map ( ( auth ) => ( {
127+ ...auth ,
128+ r : ox__Hex . fromNumber ( auth . r ) ,
129+ s : ox__Hex . fromNumber ( auth . s ) ,
130+ nonce : Number ( auth . nonce ) ,
131+ contractAddress : auth . address ,
132+ } ) ) ,
116133 } ) ,
117134 ) ;
118135 if ( options . transaction . chain . experimental ?. increaseZeroByteCount ) {
0 commit comments