@@ -232,23 +232,17 @@ func writeToFile(filename string, data []stats) error {
232232 return nil
233233}
234234
235- func timeTransaction (chainId * big.Int , privateKey * ecdsa.PrivateKey , fromAddress common.Address , toAddress common.Address , client * ethclient.Client , useSyncRPC bool , pollingIntervalMs int ) (stats , error ) {
236- // Use confirmed nonce to avoid conflicts with pending transactions
237- nonce , err := client .NonceAt (context .Background (), fromAddress , nil )
238- if err != nil {
239- return stats {}, fmt .Errorf ("unable to get nonce: %v" , err )
240- }
241-
235+ func createTx (chainId * big.Int , privateKey * ecdsa.PrivateKey , toAddress common.Address , client * ethclient.Client , nonce uint64 ) (* types.Transaction , error ) {
242236 gasPrice , err := client .SuggestGasPrice (context .Background ())
243237 if err != nil {
244- return stats {} , fmt .Errorf ("unable to get gas price: %v" , err )
238+ return nil , fmt .Errorf ("unable to get gas price: %v" , err )
245239 }
246240 gasLimit := uint64 (21000 )
247241 value := big .NewInt (100 )
248242
249243 tip , err := client .SuggestGasTipCap (context .Background ())
250244 if err != nil {
251- return stats {} , fmt .Errorf ("unable to get gas tip cap: %v" , err )
245+ return nil , fmt .Errorf ("unable to get gas tip cap: %v" , err )
252246 }
253247
254248 // Add 20% buffer to tip to ensure replacement transactions are accepted
@@ -271,7 +265,22 @@ func timeTransaction(chainId *big.Int, privateKey *ecdsa.PrivateKey, fromAddress
271265
272266 signedTx , err := types .SignTx (tx , types .NewPragueSigner (chainId ), privateKey )
273267 if err != nil {
274- return stats {}, fmt .Errorf ("unable to sign transaction: %v" , err )
268+ return nil , fmt .Errorf ("unable to sign transaction: %v" , err )
269+ }
270+
271+ return signedTx , nil
272+ }
273+
274+ func timeTransaction (chainId * big.Int , privateKey * ecdsa.PrivateKey , fromAddress common.Address , toAddress common.Address , client * ethclient.Client , useSyncRPC bool , pollingIntervalMs int ) (stats , error ) {
275+ // Use confirmed nonce to avoid conflicts with pending transactions
276+ nonce , err := client .NonceAt (context .Background (), fromAddress , nil )
277+ if err != nil {
278+ return stats {}, fmt .Errorf ("unable to get nonce: %v" , err )
279+ }
280+
281+ signedTx , err := createTx (chainId , privateKey , toAddress , client , nonce )
282+ if err != nil {
283+ return stats {}, fmt .Errorf ("unable to create transaction: %v" , err )
275284 }
276285
277286 if useSyncRPC {
@@ -385,45 +394,17 @@ func createAndSendBundle(chainId *big.Int, privateKey *ecdsa.PrivateKey, fromAdd
385394 return fmt .Errorf ("unable to get nonce: %v" , err )
386395 }
387396
388- // Get gas parameters (similar to existing code)
389- gasPrice , err := client .SuggestGasPrice (context .Background ())
390- if err != nil {
391- return fmt .Errorf ("unable to get gas price: %v" , err )
392- }
393-
394- tip , err := client .SuggestGasTipCap (context .Background ())
395- if err != nil {
396- return fmt .Errorf ("unable to get gas tip cap: %v" , err )
397- }
398-
399- // Add 20% buffer to tip to ensure replacement transactions are accepted
400- tipWithBuffer := new (big.Int ).Mul (tip , big .NewInt (120 ))
401- tipWithBuffer .Div (tipWithBuffer , big .NewInt (100 ))
402-
403- // Set GasFeeCap to baseFee + tip, with proper calculation and buffer
404- gasFeeCapWithBuffer := new (big.Int ).Mul (gasPrice , big .NewInt (2 ))
405-
406397 // Create multiple signed transactions for the bundle
407398 var signedTxs []* types.Transaction
408399 for i := 0 ; i < numTxs ; i ++ {
409- tx := types .NewTx (& types.DynamicFeeTx {
410- ChainID : chainId ,
411- Nonce : baseNonce + uint64 (i ), // Sequential nonces
412- GasTipCap : tipWithBuffer ,
413- GasFeeCap : gasFeeCapWithBuffer ,
414- Gas : 21000 ,
415- To : & toAddress ,
416- Value : big .NewInt (100 ),
417- Data : nil ,
418- })
419-
420- signedTx , err := types .SignTx (tx , types .NewPragueSigner (chainId ), privateKey )
400+ nonce := baseNonce + uint64 (i ) // Sequential nonces
401+ signedTx , err := createTx (chainId , privateKey , toAddress , client , nonce )
421402 if err != nil {
422- return fmt .Errorf ("unable to sign transaction %d: %v" , i , err )
403+ return fmt .Errorf ("unable to create transaction %d: %v" , i , err )
423404 }
424405
425406 signedTxs = append (signedTxs , signedTx )
426- log .Printf ("Created transaction %d with nonce %d, hash: %s" , i , baseNonce + uint64 ( i ) , signedTx .Hash ().Hex ())
407+ log .Printf ("Created transaction %d with nonce %d, hash: %s" , i , nonce , signedTx .Hash ().Hex ())
427408 }
428409
429410 // Send the bundle
0 commit comments