Created
May 3, 2021 13:25
-
-
Save apriori/da97168da859783da31c844b1b88715b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abigen!(WBNBContract, "https://api-testnet.bscscan.com/api?module=contract&action=getabi&address=0xae13d989dac2f0debff460ac112a837c89baa7cd&apikey=SW4QW2JXP54AXI4RZ823QX7VGVMYD2X87A&format=raw"); | |
#[tokio::main] | |
async fn main() -> Result<()> { | |
// connect to the network | |
let provider = Provider::<Http>::try_from("https://data-seed-prebsc-1-s1.binance.org:8545")?; | |
let chain = provider.get_chainid().await?; | |
let p = PathBuf::from_str("/home/user/projects/rust/bmc/wallet_ids").unwrap(); | |
let mut paths = fs::read_dir(p).unwrap(); | |
let p = paths.next().map(|x| x.unwrap()); | |
let mut rng = thread_rng(); | |
let wallet = if let Some(filePath) = p { | |
MnemonicBuilder::<English>::default() | |
.word_count(12) | |
.phrase(filePath.path()) | |
.build() | |
} | |
else { | |
MnemonicBuilder::<English>::default() | |
.word_count(12) | |
.write_to("/home/user/projects/rust/bmc/wallet_ids") | |
.build_random(&mut rng) | |
}?; | |
let wallet_addr = "$ADDR".parse::<Address>()?; | |
let client = Arc::new(provider.with_sender(wallet_addr)); | |
# token addr of BNB not WBNB | |
let address = "0x2b8ff854c5e16cf35b9a792390cc3a2a60ec9ba2".parse::<Address>()?; | |
let instance = WBNBContract::new(address, client); | |
let symbol = instance.symbol().call().await?; | |
println!("symbol: {}", symbol); | |
let supply = instance.total_supply().call().await?; | |
println!("Total supply of {}: {}", symbol, supply); | |
let decimals = instance.decimals().call().await?; | |
let balance = instance.balance_of(wallet_addr).call().await?; | |
println!("Decimals: {}", decimals); | |
//println!("{}", balance.div(10_i64.pow(decimals as u64))); | |
println!("balance: {}", balance); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment