helios/examples
Giovanni Vignone c26e393b7d
feat: add tx length rpc methods (#142)
* adding documentation for rpc.md

* adding rpc methods in table for rpc.md

* adjusting readme to link to rpc.md

* fixing grammar

* grammar

* adding RPC Methods according to documentation and listing column as Client Function

* adding more description space

* undoing description spacing

* adding get block transaction count by hash to node.rs and rpc.rs

* functioning getblocktransactioncountbyhash function

* removing documentation

* adding second rpc method and simplifying logic

* adjusting example and node.rs

* formatting

* fixing clippy errors

* adding to client and to rpc.md

* formatting

* integrating into client

* u64 return types, rpc.md updated to get_nonce, get_transaction_count -> get_nonce revert

* cargo fmt
2022-12-13 19:19:36 -05:00
..
checkpoints.rs fix(readme): Resolve Dependency Type Conflicts (#129) 2022-12-04 15:28:44 -05:00
client.rs feat(examples): Introduces working examples (#126) 2022-12-02 18:41:50 -05:00
config.rs fix(readme): Resolve Dependency Type Conflicts (#129) 2022-12-04 15:28:44 -05:00
readme.rs feat: add tx length rpc methods (#142) 2022-12-13 19:19:36 -05:00

readme.rs

use std::str::FromStr;

use env_logger::Env;
use ethers::{types::Address, utils};
use eyre::Result;
use helios::{client::ClientBuilder, config::networks::Network, types::BlockTag};

#[tokio::main]
async fn main() -> Result<()> {
    env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();

    let untrusted_rpc_url = "https://eth-mainnet.g.alchemy.com/v2/<YOUR_API_KEY>";
    log::info!("Using untrusted RPC URL [REDACTED]");

    let consensus_rpc = "https://www.lightclientdata.org";
    log::info!("Using consensus RPC URL: {}", consensus_rpc);

    let mut client = ClientBuilder::new()
        .network(Network::MAINNET)
        .consensus_rpc(consensus_rpc)
        .execution_rpc(untrusted_rpc_url)
        .load_external_fallback()
        .build()?;
    log::info!(
        "Built client on network \"{}\" with external checkpoint fallbacks",
        Network::MAINNET
    );

    client.start().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?;

    log::info!("synced up to block: {}", head_block_num);
    log::info!(
        "balance of deposit contract: {}",
        utils::format_ether(balance)
    );

    Ok(())
}