Skip to content

Instantly share code, notes, and snippets.

@AshiqAmien
Last active December 12, 2025 06:42
Show Gist options
  • Select an option

  • Save AshiqAmien/c0d0d7b584a2a2d04796686df56281df to your computer and use it in GitHub Desktop.

Select an option

Save AshiqAmien/c0d0d7b584a2a2d04796686df56281df to your computer and use it in GitHub Desktop.
Rust loop for sunrise
loop {
// Prepare the tx before sending it the transaction
let tx = Eip1559TransactionRequest::new()
.to("0xD1A0060ba708BC4BCD3DA6C37EFa8deDF015FB70".parse::<Address>()?)
.data(Bytes::from(calldata.clone()))
.gas(U256::from(6_000_000u64))
.max_fee_per_gas(U256::from(8_000_000_0u64)) // 0.8 Gwei
.max_priority_fee_per_gas(U256::from(1_800_000_00u64)); // 0.18 Gwei
// Get current time and calculate time until next hour
let now: DateTime<Utc> = Utc::now();
let next_hour = now + chrono::Duration::hours(1);
let next_hour = next_hour.with_minute(0).unwrap().with_second(0).unwrap();
let duration_until_next_hour = next_hour.signed_duration_since(now);
println!("Waiting until next hour: {}", next_hour);
sleep(Duration::from_secs(duration_until_next_hour.num_seconds() as u64)).await;
//this is to prevent more than 1 tx per hour.
match client.send_transaction(tx, None).await {
Ok(tx_hash) => {
println!("Successfully sent transaction. Hash: {:?}", tx_hash);
},
Err(e) => {
println!("Error sending transaction: {:?}", e);
}
}
// Wait 1 minute before trying again
println!("Waiting 1 minute before next call...");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment