@@ -98,7 +98,7 @@ func (args *TransactionArgs) data() []byte {
98
98
}
99
99
100
100
// setDefaults fills in default values for unspecified tx fields.
101
- func (args * TransactionArgs ) setDefaults (ctx context.Context , b Backend ) error {
101
+ func (args * TransactionArgs ) setDefaults (ctx context.Context , b Backend , skipGasEstimation bool ) error {
102
102
if err := args .setBlobTxSidecar (ctx ); err != nil {
103
103
return err
104
104
}
@@ -138,30 +138,37 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
138
138
}
139
139
}
140
140
141
- // Estimate the gas usage if necessary.
142
141
if args .Gas == nil {
143
- // These fields are immutable during the estimation, safe to
144
- // pass the pointer directly.
145
- data := args .data ()
146
- callArgs := TransactionArgs {
147
- From : args .From ,
148
- To : args .To ,
149
- GasPrice : args .GasPrice ,
150
- MaxFeePerGas : args .MaxFeePerGas ,
151
- MaxPriorityFeePerGas : args .MaxPriorityFeePerGas ,
152
- Value : args .Value ,
153
- Data : (* hexutil .Bytes )(& data ),
154
- AccessList : args .AccessList ,
155
- BlobFeeCap : args .BlobFeeCap ,
156
- BlobHashes : args .BlobHashes ,
157
- }
158
- latestBlockNr := rpc .BlockNumberOrHashWithNumber (rpc .LatestBlockNumber )
159
- estimated , err := DoEstimateGas (ctx , b , callArgs , latestBlockNr , nil , b .RPCGasCap ())
160
- if err != nil {
161
- return err
142
+ if skipGasEstimation { // Skip gas usage estimation if a precise gas limit is not critical, e.g., in non-transaction calls.
143
+ gas := hexutil .Uint64 (b .RPCGasCap ())
144
+ if gas == 0 {
145
+ gas = hexutil .Uint64 (math .MaxUint64 / 2 )
146
+ }
147
+ args .Gas = & gas
148
+ } else { // Estimate the gas usage otherwise.
149
+ // These fields are immutable during the estimation, safe to
150
+ // pass the pointer directly.
151
+ data := args .data ()
152
+ callArgs := TransactionArgs {
153
+ From : args .From ,
154
+ To : args .To ,
155
+ GasPrice : args .GasPrice ,
156
+ MaxFeePerGas : args .MaxFeePerGas ,
157
+ MaxPriorityFeePerGas : args .MaxPriorityFeePerGas ,
158
+ Value : args .Value ,
159
+ Data : (* hexutil .Bytes )(& data ),
160
+ AccessList : args .AccessList ,
161
+ BlobFeeCap : args .BlobFeeCap ,
162
+ BlobHashes : args .BlobHashes ,
163
+ }
164
+ latestBlockNr := rpc .BlockNumberOrHashWithNumber (rpc .LatestBlockNumber )
165
+ estimated , err := DoEstimateGas (ctx , b , callArgs , latestBlockNr , nil , b .RPCGasCap ())
166
+ if err != nil {
167
+ return err
168
+ }
169
+ args .Gas = & estimated
170
+ log .Trace ("Estimate gas usage automatically" , "gas" , args .Gas )
162
171
}
163
- args .Gas = & estimated
164
- log .Trace ("Estimate gas usage automatically" , "gas" , args .Gas )
165
172
}
166
173
167
174
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
0 commit comments