I am trying to use Rust (not Typescript) to query Solana and retrieve the SOL balance of a given account.
But I can't seem to be able to do this. What I have thus far. As dependencies I have the following:
[dependencies]
borsh = "0.9.3"
solana-client = "1.14.1"
solana-sdk = "1.14.1"
solana-program = "1.14.1"
Then in code I have the following:
use solana_sdk::commitment_config::CommitmentConfig;
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;
#[test]
fn get_price() {
let rpc = RpcClient::new("https://api.devnet.solana.com".to_string());
let balance = rpc.get_account(&Pubkey::new(b"BQeizWYD2dHmQq1b6HQqwBPrLWKitnhv5K82ZnRNPL8z")).unwrap().lamports;
dbg!(balance);
}
But this fails with thread 'get_price' panicked at 'Slice must be the same length as a Pubkey: TryFromSliceError(())'
What am I doing wrong? And how do I get the SOL balance given that I have the public key (i.e. the address) using Rust?