Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not deserialize the block number in hex format #18

Open
thanhpp opened this issue Dec 4, 2023 · 0 comments
Open

Can not deserialize the block number in hex format #18

thanhpp opened this issue Dec 4, 2023 · 0 comments
Milestone

Comments

@thanhpp
Copy link

thanhpp commented Dec 4, 2023

Hi, I'm using this library to get the ERC20TokenTransferEvent from etherscan and then save it into a JSON file.
But when deserialize the JSON file, I had this Error value: Error("digit 33 is out of range for base 16", line: 3, column: 39)'. It seems like the number in the JSON file is saved in the hex format.
Can someone help me to solve this issue?

Test code

mod test {
    use std::str::FromStr;

    use alloy_chains::Chain;
    use alloy_primitives::Address;
    use foundry_block_explorers::{account::ERC20TokenTransferEvent, Client};

    #[tokio::test]
    async fn test_serde() {
        let client = Client::new(Chain::from_id(137), "<API-KEY>>").unwrap();
        let addr = Address::from_str("<Address>").unwrap();

        let events = client
            .get_erc20_token_transfer_events(
                foundry_block_explorers::account::TokenQueryOption::ByAddress(addr),
                Some(foundry_block_explorers::account::TxListParams {
                    start_block: 0,
                    end_block: 99999999,
                    page: 1,
                    offset: 1,
                    sort: foundry_block_explorers::account::Sort::Desc,
                }),
            )
            .await
            .unwrap();

        let data = serde_json::to_string_pretty(&events).unwrap();

        println!("{}", data);

        let de_events: Vec<ERC20TokenTransferEvent> = serde_json::from_str(&data).unwrap();

        assert_eq!(events.len(), de_events.len())
    }
}

Cargo.toml

[dependencies]
alloy-chains = "0.1.4"
alloy-primitives = { version = "0.5.2", features = ["serde", "std"] }
alloy-json-abi = { version = "0.5", default-features = false, features = [
    "std",
    "serde_json",
] }
anyhow = "1.0.75"
foundry-block-explorers = "0.1.1"
rust_decimal = { version = "1.33.1", features = ["maths"] }
serde = "1.0.193"
serde_json = "1.0.108"
tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] }
@zerosnacks zerosnacks added this to the v1.0.0 milestone Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants