| Crates.io | bscscan_client |
| lib.rs | bscscan_client |
| version | 0.1.0 |
| created_at | 2024-12-01 15:38:24.394795+00 |
| updated_at | 2024-12-01 15:38:24.394795+00 |
| description | bscscan api client |
| homepage | |
| repository | https://github.com/cfping/bscscan_client |
| max_upload_size | |
| id | 1467596 |
| size | 112,953 |
First, add bscscan_client to your Cargo.toml file:
[dependencies]
bscscan_client = "0.1.0"
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);
}
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),
}
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),
}
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),
}
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),
}
}
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),
}
If you find any issues or have improvement suggestions, feel free to submit an Issue or Pull Request.
This project is licensed under the MIT License.
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!