alloy-rs / examples

Example code for using alloy and alloy-core
Apache License 2.0
133 stars 32 forks source link

Add example of using AnyNetwork type and populating customData in WithOtherFields #85

Closed zerosnacks closed 4 months ago

zerosnacks commented 5 months ago

Relevant in the context of op-alloy and the requested usecase of ZKSync's Paymaster

Related: https://t.me/ethers_rs/38142

alexfertel commented 4 months ago

I had to do this today for Arbitrum receipts:


#[derive(Debug, Deserialize)]
struct ArbOtherFields {
    #[serde(rename = "gasUsedForL1")]
    gas_used_for_l1: U128,
}

// ...

let alice_wallet = ProviderBuilder::new()
    .network::<AnyNetwork>()
    .with_recommended_fillers()
    .wallet(EthereumWallet::from(alice.signer.clone()))
    .on_http(alice.url().parse()?);

// ...

let arb_fields: ArbOtherFields = receipt.other.deserialize_into()?;
let l1_gas = arb_fields.gas_used_for_l1.to::<u128>();

Let me know if it makes sense to convert this into an example.

zerosnacks commented 4 months ago

Hey @alexfertel, that would be great!

This example is part of the advanced examples, see: https://github.com/alloy-rs/examples/issues/87