forked from a16z/helios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.rs
More file actions
61 lines (47 loc) · 2.07 KB
/
Copy pathbasic.rs
File metadata and controls
61 lines (47 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::{path::PathBuf, str::FromStr, time::Duration};
use alloy::eips::BlockNumberOrTag;
use alloy::primitives::{utils::format_ether, Address};
use eyre::Result;
use tracing::info;
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
use tracing_subscriber::FmtSubscriber;
use helios::ethereum::{config::networks::Network, EthereumClient, EthereumClientBuilder};
#[tokio::main]
async fn main() -> Result<()> {
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env()
.expect("invalid env filter");
let subscriber = FmtSubscriber::builder()
.with_env_filter(env_filter)
.finish();
tracing::subscriber::set_global_default(subscriber).expect("subscriber set failed");
let untrusted_rpc_url = "https://eth-mainnet.g.alchemy.com/v2/<YOUR_API_KEY>";
info!("Using untrusted RPC URL [REDACTED]");
let consensus_rpc = "http://testing.mainnet.beacon-api.nimbus.team";
info!("Using consensus RPC URL: {}", consensus_rpc);
let client: EthereumClient = EthereumClientBuilder::new()
.network(Network::Mainnet)
.consensus_rpc(consensus_rpc)?
.execution_rpc(untrusted_rpc_url)?
.load_external_fallback()
.data_dir(PathBuf::from("/tmp/helios"))
.with_file_db()
.build()?;
info!(
"Built client on network \"{}\" with external checkpoint fallbacks",
Network::Mainnet
);
client.wait_synced().await?;
// Wait for a fresh block (Ethereum produces blocks every ~12 seconds)
tokio::time::sleep(Duration::from_secs(15)).await;
let client_version = client.get_client_version().await;
let head_block_num = client.get_block_number().await?;
let addr = Address::from_str("0x00000000219ab540356cBB839Cbe05303d7705Fa")?;
let block = BlockNumberOrTag::Latest;
let balance = client.get_balance(addr, block.into()).await?;
info!("client version: {}", client_version);
info!("synced up to block: {}", head_block_num);
info!("balance of deposit contract: {}", format_ether(balance));
Ok(())
}