diff --git a/examples/rust/get_metadata/Cargo.toml b/examples/rust/get_metadata/Cargo.toml new file mode 100644 index 00000000..4400f54a --- /dev/null +++ b/examples/rust/get_metadata/Cargo.toml @@ -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" \ No newline at end of file diff --git a/examples/rust/get_metadata/src/main.rs b/examples/rust/get_metadata/src/main.rs new file mode 100644 index 00000000..1dfd4e58 --- /dev/null +++ b/examples/rust/get_metadata/src/main.rs @@ -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); +}