forked from a16z/helios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.rs
60 lines (47 loc) · 1.93 KB
/
basic.rs
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
use std::{path::PathBuf, str::FromStr};
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::core::types::BlockTag;
use helios::ethereum::{
config::networks::Network, database::FileDB, 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 = "https://www.lightclientdata.org";
info!("Using consensus RPC URL: {}", consensus_rpc);
let mut client: EthereumClient<FileDB> = EthereumClientBuilder::new()
.network(Network::MAINNET)
.consensus_rpc(consensus_rpc)
.execution_rpc(untrusted_rpc_url)
.load_external_fallback()
.data_dir(PathBuf::from("/tmp/helios"))
.build()?;
info!(
"Built client on network \"{}\" with external checkpoint fallbacks",
Network::MAINNET
);
client.start().await?;
client.wait_synced().await;
let client_version = client.client_version().await;
let head_block_num = client.get_block_number().await?;
let addr = Address::from_str("0x00000000219ab540356cBB839Cbe05303d7705Fa")?;
let block = BlockTag::Latest;
let balance = client.get_balance(addr, block).await?;
info!("client version: {}", client_version);
info!("synced up to block: {}", head_block_num);
info!("balance of deposit contract: {}", format_ether(balance));
Ok(())
}