Skip to content

Commit f6e6c55

Browse files
authored
Estimate gas for no-op self-transfer transaction (#103)
Replace the hardcoded 21k gas limit for the noop self-send with a runtime estimate from the provider. Make the request mutable, call chain.provider().estimate_gas(tx_request.clone()) and fall back to 21000 if estimation fails. This handles chains that charge more than the standard 21k and preserves the subsequent fee estimation and tx building logic.
1 parent 7762469 commit f6e6c55

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

executors/src/eoa/worker/transaction.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,23 @@ impl<C: Chain> EoaExecutorWorker<C> {
127127
// Send 0 ETH to self with minimal gas
128128

129129
// Build no-op transaction (send 0 to self)
130-
let tx_request = AlloyTransactionRequest::default()
130+
let mut tx_request = AlloyTransactionRequest::default()
131131
.with_from(self.eoa)
132132
.with_to(self.eoa) // Send to self
133133
.with_value(U256::ZERO) // Send 0 value
134134
.with_input(Bytes::new()) // No data
135135
.with_chain_id(self.chain.chain_id())
136-
.with_nonce(nonce)
137-
.with_gas_limit(21000); // Minimal gas for basic transfer
136+
.with_nonce(nonce);
137+
138+
// Estimate gas for the noop — some chains charge
139+
// significantly more than the standard 21k for a basic transfer.
140+
let gas_limit = self
141+
.chain
142+
.provider()
143+
.estimate_gas(tx_request.clone())
144+
.await
145+
.unwrap_or(21000);
146+
tx_request = tx_request.with_gas_limit(gas_limit);
138147

139148
let tx_request = self.estimate_gas_fees(tx_request).await?;
140149
let built_tx = tx_request.build_typed_tx().map_err(|e| {

0 commit comments

Comments
 (0)