Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple get metadata example #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/rust/get_metadata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "get_metadata"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread","full"] }
mpl-token-metadata = "4.1.2"
solana-client = "1.17.14"
solana-sdk = "1.17.14"
21 changes: 21 additions & 0 deletions examples/rust/get_metadata/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use solana_client::nonblocking::rpc_client::RpcClient;
use mpl_token_metadata::accounts::Metadata;
use solana_sdk::pubkey::Pubkey;

#[tokio::main(flavor = "multi_thread")]
async fn main() {
let conn = RpcClient::new("https://api.mainnet-beta.solana.com".to_string());

// USDC https://solscan.io/token/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
let token: Pubkey = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".parse().unwrap();

let (metadata_account, _) = Metadata::find_pda(&token);
dbg!(metadata_account);

let account = conn.get_account(&metadata_account).await.unwrap();

dbg!(&account);

let meta_data = Metadata::safe_deserialize(&account.data).unwrap();
dbg!(meta_data);
}