-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathnft_owner.rs
51 lines (40 loc) · 1.36 KB
/
nft_owner.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use solana_client::rpc_client::RpcClient;
use solana_sdk::account::ReadableAccount;
use solana_sdk::{program_pack::Pack, pubkey::Pubkey};
#[derive(serde::Deserialize)]
struct Env {
rpc_url: url::Url,
mint_account_pubkey: String,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let env = envy::from_env::<Env>()?;
let client = RpcClient::new(env.rpc_url.to_string());
let mint: Pubkey = env.mint_account_pubkey.parse()?;
let res = get_token_largest_accounts(&client, &mint)?;
let addr: Pubkey = res
.value
.first()
.ok_or("No token accounts found!")?
.address
.parse()?;
let account = client.get_account(&addr)?;
let token = spl_token::state::Account::unpack(&mut account.data())?;
println!("{} owner:\n{}", mint.to_string(), token.owner);
Ok(())
}
#[derive(serde::Deserialize)]
struct RpcTokenAccounts {
address: String,
//amount: String,
//decimals: u8,
}
fn get_token_largest_accounts(
rpc: &RpcClient,
mint_address: &Pubkey,
) -> Result<solana_client::rpc_response::Response<Vec<RpcTokenAccounts>>, Box<dyn std::error::Error>>
{
let method = "getTokenLargestAccounts";
let request = solana_client::rpc_request::RpcRequest::Custom { method };
let params = serde_json::json!([mint_address.to_string()]);
rpc.send(request, params).map_err(|e| e.into())
}