bscscan_client

Crates.iobscscan_client
lib.rsbscscan_client
version
sourcesrc
created_at2024-12-01 15:38:24.394795
updated_at2024-12-01 15:38:24.394795
descriptionbscscan api client
homepage
repositoryhttps://github.com/cfping/bscscan_client
max_upload_size
id1467596
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(cfping)

documentation

README

BscScanRustClient Usage Documentation

中文

1. Installation

First, add bscscan_client to your Cargo.toml file:

[dependencies]
bscscan_client = "0.1.0"

2. Initialize the Client

Before using bscscan_client, you need to initialize a client instance. You need to provide your BscScan API key.

use bscscan_client::BscScanClient;

#[tokio::main]
async fn main() {
    let api_key = "YOUR_BSCSCAN_API_KEY";
    let client = BscScanClient::new(api_key);
}

3. Get BNB Balance

You can use the get_bnb_balance method to get the BNB balance of a specified address.

match client.get_bnb_balance("0xYourAddress").await {
    Ok(balance) => println!("BNB Balance: {}", balance),
    Err(e) => eprintln!("Error: {}", e),
}

4. Get Normal Transaction List

You can use the get_normal_transactions method to get the normal transaction list of a specified address.

match client.get_normal_transactions("0xYourAddress","0","99999999").await {
    Ok(transactions) => {
        for tx in transactions {
            println!("Transaction: {:?}", tx);
        }
    },
    Err(e) => eprintln!("Error: {}", e),
}

5. Get Internal Transaction List

You can use the get_internal_transactions method to get the internal transaction list of a specified address.

match client.get_internal_transactions("0xYourAddress","0","99999999").await {
    Ok(transactions) => {
        for tx in transactions {
            println!("Internal Transaction: {:?}", tx);
        }
    },
    Err(e) => eprintln!("Error: {}", e),
}

6. Example Code

Here is a complete example code showing how to use BscScanRustClient to get the BNB balance, normal transaction list, and internal transaction list.

use bscscan_client::BscScanClient;

#[tokio::main]
async fn main() {
    let api_key = "YOUR_BSCSCAN_API_KEY";
    let client = BscScanClient::new(api_key);

    // Get BNB Balance
    match client.get_bnb_balance("0xYourAddress").await {
        Ok(balance) => println!("BNB Balance: {}", balance),
        Err(e) => eprintln!("Error: {}", e),
    }

    // Get Normal Transaction List
    match client.get_normal_transactions("0xYourAddress","0","99999999").await {
        Ok(transactions) => {
            for tx in transactions {
                println!("Transaction: {:?}", tx);
            }
        },
        Err(e) => eprintln!("Error: {}", e),
    }

    // Get Internal Transaction List
    match client.get_internal_transactions("0xYourAddress","0","99999999").await {
        Ok(transactions) => {
            for tx in transactions {
                println!("Internal Transaction: {:?}", tx);
            }
        },
        Err(e) => eprintln!("Error: {}", e),
    }
}

7. Error Handling

Always handle possible errors when calling API methods. Each method returns a Result, and you can use match or the ? operator to handle errors.

match client.get_bnb_balance("0xYourAddress").await {
    Ok(balance) => println!("BNB Balance: {}", balance),
    Err(e) => eprintln!("Error: {}", e),
}

8. Contributing

If you find any issues or have improvement suggestions, feel free to submit an Issue or Pull Request.

9. License

This project is licensed under the MIT License.

10. Disclaimer

This project is for Rust learning and research purposes only.


With these steps, you should be able to use the bscscan_client library to interact with the BNB community API. We hope this information is helpful!

Commit count: 5

cargo fmt