From 9fc9bb0d6b2bbf6878521dca459b7cc07a34a99a Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:06:02 +0200 Subject: [PATCH] fix: set tx nonce and sender --- bolt-spammer-helder/src/main.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bolt-spammer-helder/src/main.rs b/bolt-spammer-helder/src/main.rs index 54b4fb635..5ed1dcbb6 100644 --- a/bolt-spammer-helder/src/main.rs +++ b/bolt-spammer-helder/src/main.rs @@ -1,10 +1,9 @@ -use std::str::FromStr; - use alloy::{ eips::eip2718::Encodable2718, hex, network::{EthereumWallet, TransactionBuilder}, primitives::{keccak256, Address}, + providers::{Provider, ProviderBuilder}, signers::{local::PrivateKeySigner, Signer}, }; use beacon_api_client::mainnet::Client as BeaconApiClient; @@ -27,7 +26,7 @@ use crate::{ struct Opts { /// EL node URL to send transactions to #[clap(short = 'p', long, default_value = "https://rpc.helder-devnets.xyz", env)] - el_provider_url: String, + el_provider_url: Url, /// CL node URL to fetch the beacon chain info from #[clap(short = 'c', long, default_value = "http://localhost:4000", env)] beacon_client_url: Url, @@ -47,15 +46,17 @@ async fn main() -> Result<()> { tracing_subscriber::fmt::init(); tracing::info!("starting bolt-spammer-helder"); - let _ = dotenvy::dotenv()?; + let _ = dotenvy::dotenv(); let opts = Opts::parse(); let wallet: PrivateKeySigner = opts.private_key.parse().expect("should parse private key"); let transaction_signer: EthereumWallet = wallet.clone().into(); + let provider = ProviderBuilder::new().on_http(opts.el_provider_url.clone()); + let sender = wallet.address(); let beacon_api_client = BeaconApiClient::new(opts.beacon_client_url); - let registry = BoltRegistry::new(Url::from_str(&opts.el_provider_url)?, opts.registry_address); + let registry = BoltRegistry::new(opts.el_provider_url, opts.registry_address); let current_slot = current_slot(&beacon_api_client).await?; @@ -87,7 +88,9 @@ async fn main() -> Result<()> { } }; - let tx = if opts.blob { generate_random_blob_tx() } else { generate_random_tx() }; + let mut tx = if opts.blob { generate_random_blob_tx() } else { generate_random_tx() }; + tx.set_from(sender); + tx.set_nonce(provider.get_transaction_count(sender).await?); let tx_signed = tx.build(&transaction_signer).await?; let tx_hash = tx_signed.tx_hash().to_string();