These examples read the PYUSD mint and the USDC metadata account, which exist
only on mainnet. Run them against a Surfpool local network that forks mainnet
(
surfpool start --network mainnet fetches the accounts on demand), or point
the RPC URL at a mainnet endpoint.Fetch Mint Account
- Kit
- Web3.js v3
- Rust
- Python
- Go
- Web3.js (legacy)
Kit
import { type Address, createSolanaRpc } from "@solana/kit";
import { fetchMint } from "@solana-program/token-2022";
const rpc = createSolanaRpc("http://localhost:8899");
const address = "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo" as Address;
const mint = await fetchMint(rpc, address);
console.log(mint);
Output from a local Surfpool network
Output
{
executable: false,
lamports: 2078412093n,
programAddress: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
space: 866n,
address: '2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo',
data: {
mintAuthority: {
__option: 'Some',
value: '8Jornc27vtAYPkwDzsZVgLQchAYyC8nD7aCNPCDV8Qk2'
},
supply: 670662348088952n,
decimals: 6,
isInitialized: true,
freezeAuthority: {
__option: 'Some',
value: '2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk'
},
extensions: { __option: 'Some', value: [Array] }
},
exists: true
}
Web3.js v3
import { Connection, PublicKey } from "@solana/web3.js";
import { getMintDecoder } from "@solana-program/token-2022";
const connection = new Connection("http://localhost:8899", "confirmed");
const mintAddress = new PublicKey(
"2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo",
);
const mintAccountInfo = await connection.getAccountInfo(
mintAddress,
"confirmed",
);
const mintAccount = getMintDecoder().decode(mintAccountInfo!.data);
console.log(mintAccount);
Output from a local Surfpool network
Output
{
mintAuthority: {
__option: 'Some',
value: 'AxJkHRY3puoofyj7Pn512M1SGBgWroXMkEdNPQypkzbu'
},
supply: 689767591884463n,
decimals: 6,
isInitialized: true,
freezeAuthority: {
__option: 'Some',
value: '2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk'
},
extensions: {
__option: 'Some',
value: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
]
}
}
Rust
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;
use solana_sdk::pubkey;
use spl_token_2022_interface::{
extension::{
confidential_transfer::ConfidentialTransferMint,
confidential_transfer_fee::ConfidentialTransferFeeConfig,
metadata_pointer::MetadataPointer, mint_close_authority::MintCloseAuthority,
permanent_delegate::PermanentDelegate, transfer_fee::TransferFeeConfig,
transfer_hook::TransferHook, BaseStateWithExtensions, ExtensionType, StateWithExtensions,
},
state::Mint,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = RpcClient::new_with_commitment(
String::from("http://localhost:8899"),
CommitmentConfig::confirmed(),
);
let mint_address = pubkey!("2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo");
let mint_data = client.get_account_data(&mint_address).await?;
let mint = StateWithExtensions::<Mint>::unpack(&mint_data)?;
println!("Mint address: {:#?}", mint_address);
println!("{:#?}\n", mint.base);
let extension_types = mint.get_extension_types()?;
println!("Extensions enabled: {:#?}\n", extension_types);
extension_types
.iter()
.for_each(|extension_type| match extension_type {
ExtensionType::TransferFeeConfig => {
if let Ok(ext) = mint.get_extension::<TransferFeeConfig>() {
println!("{:#?}\n", ext);
}
}
ExtensionType::MintCloseAuthority => {
if let Ok(ext) = mint.get_extension::<MintCloseAuthority>() {
println!("{:#?}\n", ext);
}
}
ExtensionType::PermanentDelegate => {
if let Ok(ext) = mint.get_extension::<PermanentDelegate>() {
println!("{:#?}\n", ext);
}
}
ExtensionType::ConfidentialTransferMint => {
if let Ok(ext) = mint.get_extension::<ConfidentialTransferMint>() {
println!("{:#?}\n", ext);
}
}
ExtensionType::ConfidentialTransferFeeConfig => {
if let Ok(ext) = mint.get_extension::<ConfidentialTransferFeeConfig>() {
println!("{:#?}\n", ext);
}
}
ExtensionType::TransferHook => {
if let Ok(ext) = mint.get_extension::<TransferHook>() {
println!("{:#?}\n", ext);
}
}
ExtensionType::MetadataPointer => {
if let Ok(ext) = mint.get_extension::<MetadataPointer>() {
println!("{:#?}\n", ext);
}
}
_ => {
println!("{:?}: (not handled)\n", extension_type);
}
});
Ok(())
}
Output from a local Surfpool network
Output
Mint address: 2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo
Mint {
mint_authority: Some(
8Jornc27vtAYPkwDzsZVgLQchAYyC8nD7aCNPCDV8Qk2,
),
supply: 670662348088952,
decimals: 6,
is_initialized: true,
freeze_authority: Some(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
}
Extensions enabled: [
MintCloseAuthority,
PermanentDelegate,
TransferFeeConfig,
ConfidentialTransferMint,
ConfidentialTransferFeeConfig,
TransferHook,
MetadataPointer,
TokenMetadata,
]
MintCloseAuthority {
close_authority: OptionalNonZeroPubkey(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
}
PermanentDelegate {
delegate: OptionalNonZeroPubkey(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
}
TransferFeeConfig {
transfer_fee_config_authority: OptionalNonZeroPubkey(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
withdraw_withheld_authority: OptionalNonZeroPubkey(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
withheld_amount: PodU64(
[
0,
0,
0,
0,
0,
0,
0,
0,
],
),
older_transfer_fee: TransferFee {
epoch: PodU64(
[
93,
2,
0,
0,
0,
0,
0,
0,
],
),
maximum_fee: PodU64(
[
0,
0,
0,
0,
0,
0,
0,
0,
],
),
transfer_fee_basis_points: PodU16(
[
0,
0,
],
),
},
newer_transfer_fee: TransferFee {
epoch: PodU64(
[
93,
2,
0,
0,
0,
0,
0,
0,
],
),
maximum_fee: PodU64(
[
0,
0,
0,
0,
0,
0,
0,
0,
],
),
transfer_fee_basis_points: PodU16(
[
0,
0,
],
),
},
}
ConfidentialTransferMint {
authority: OptionalNonZeroPubkey(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
auto_approve_new_accounts: PodBool(
0,
),
auditor_elgamal_pubkey: OptionalNonZeroElGamalPubkey(
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
),
}
ConfidentialTransferFeeConfig {
authority: OptionalNonZeroPubkey(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
withdraw_withheld_authority_elgamal_pubkey: [28, 55, 230, 67, 59, 115, 4, 221, 130, 115, 122, 228, 13, 155, 139, 243, 196, 159, 91, 14, 108, 73, 168, 213, 51, 40, 179, 229, 6, 144, 28, 87],
harvest_to_mint_enabled: PodBool(
1,
),
withheld_amount: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
}
TransferHook {
authority: OptionalNonZeroPubkey(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
program_id: OptionalNonZeroPubkey(
11111111111111111111111111111111,
),
}
MetadataPointer {
authority: OptionalNonZeroPubkey(
2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk,
),
metadata_address: OptionalNonZeroPubkey(
2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo,
),
}
TokenMetadata: (not handled)
Python
import asyncio
import json
from solana.rpc.async_api import AsyncClient
from solders.pubkey import Pubkey
async def main():
async with AsyncClient("http://localhost:8899") as client:
address = Pubkey.from_string("2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo")
mint = await client.get_account_info_json_parsed(address)
print(json.dumps(json.loads(mint.value.to_json()), indent=2))
asyncio.run(main())
Output from a local Surfpool network
Output
{
"lamports": 2078412093,
"data": {
"program": "spl-token-2022",
"parsed": {
"info": {
"decimals": 6,
"extensions": [
{
"extension": "mintCloseAuthority",
"state": {
"closeAuthority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk"
}
},
{
"extension": "permanentDelegate",
"state": {
"delegate": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk"
}
},
{
"extension": "transferFeeConfig",
"state": {
"newerTransferFee": {
"epoch": 605,
"maximumFee": 0,
"transferFeeBasisPoints": 0
},
"olderTransferFee": {
"epoch": 605,
"maximumFee": 0,
"transferFeeBasisPoints": 0
},
"transferFeeConfigAuthority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"withdrawWithheldAuthority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"withheldAmount": 0
}
},
{
"extension": "confidentialTransferMint",
"state": {
"auditorElgamalPubkey": null,
"authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"autoApproveNewAccounts": false
}
},
{
"extension": "confidentialTransferFeeConfig",
"state": {
"authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"harvestToMintEnabled": true,
"withdrawWithheldAuthorityElgamalPubkey": "HDfmQztzBN2Cc3rkDZuL88SfWw5sSajVMyiz5QaQHFc=",
"withheldAmount": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
}
},
{
"extension": "transferHook",
"state": {
"authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"programId": null
}
},
{
"extension": "metadataPointer",
"state": {
"authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"metadataAddress": "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo"
}
},
{
"extension": "tokenMetadata",
"state": {
"additionalMetadata": [],
"mint": "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo",
"name": "PayPal USD",
"symbol": "PYUSD",
"updateAuthority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"uri": "https://token-metadata.paxos.com/pyusd_metadata/prod/solana/pyusd_metadata.json"
}
}
],
"freezeAuthority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"isInitialized": true,
"mintAuthority": "AxJkHRY3puoofyj7Pn512M1SGBgWroXMkEdNPQypkzbu",
"supply": "691374793439163"
},
"type": "mint"
},
"space": 866
},
"owner": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
"executable": false,
"rentEpoch": 18446744073709551615
}
Go
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/solana-foundation/solana-go/v2"
token2022 "github.com/solana-foundation/solana-go/v2/programs/token-2022"
"github.com/solana-foundation/solana-go/v2/rpc"
)
func main() {
client := rpc.New("http://localhost:8899")
address := solana.MustPublicKeyFromBase58("2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo")
info, err := client.GetAccountInfo(context.Background(), address)
if err != nil {
panic(err)
}
mint, _, err := token2022.ParseMintWithExtensions(info.Value.Data.GetBinary())
if err != nil {
panic(err)
}
out, _ := json.MarshalIndent(mint, "", " ")
fmt.Println(string(out))
}
Output from a local Surfpool network
Output
{
"MintAuthority": "AxJkHRY3puoofyj7Pn512M1SGBgWroXMkEdNPQypkzbu",
"Supply": 691374793439163,
"Decimals": 6,
"IsInitialized": true,
"FreezeAuthority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk"
}
Web3.js (legacy)
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.import { Connection, PublicKey } from "@solana/web3.js";
import { getMint, TOKEN_2022_PROGRAM_ID } from "@solana/spl-token";
const connection = new Connection("http://localhost:8899", "confirmed");
const mintAddress = new PublicKey(
"2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo",
);
const mintAccount = await getMint(
connection,
mintAddress,
undefined,
TOKEN_2022_PROGRAM_ID,
);
console.log(
JSON.stringify(
{
...mintAccount,
supply: mintAccount.supply.toString(),
},
null,
2,
),
);
Output from a local Surfpool network
Output
{
"address": "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo",
"mintAuthority": "8Jornc27vtAYPkwDzsZVgLQchAYyC8nD7aCNPCDV8Qk2",
"supply": "681206899588952",
"decimals": 6,
"isInitialized": true,
"freezeAuthority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk",
"tlvData": {
"type": "Buffer",
"data": [
3,
0,
32,
0,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
12,
0,
32,
0,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
1,
0,
108,
0,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
0,
0,
0,
0,
0,
0,
0,
0,
93,
2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
93,
2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
4,
0,
65,
0,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
129,
0,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
28,
55,
230,
67,
59,
115,
4,
221,
130,
115,
122,
228,
13,
155,
139,
243,
196,
159,
91,
14,
108,
73,
168,
213,
51,
40,
179,
229,
6,
144,
28,
87,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
14,
0,
64,
0,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
18,
0,
64,
0,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
23,
146,
72,
59,
108,
138,
42,
135,
183,
71,
29,
129,
79,
149,
145,
249,
57,
92,
132,
10,
156,
227,
217,
244,
213,
186,
125,
58,
75,
138,
116,
158,
19,
0,
174,
0,
23,
133,
50,
97,
239,
106,
184,
83,
42,
103,
240,
83,
134,
90,
173,
49,
41,
63,
207,
7,
207,
18,
10,
181,
185,
161,
87,
6,
84,
141,
192,
43,
23,
146,
72,
59,
108,
138,
42,
135,
183,
71,
29,
129,
79,
149,
145,
249,
57,
92,
132,
10,
156,
227,
217,
244,
213,
186,
125,
58,
75,
138,
116,
158,
10,
0,
0,
0,
80,
97,
121,
80,
97,
108,
32,
85,
83,
68,
5,
0,
0,
0,
80,
89,
85,
83,
68,
79,
0,
0,
0,
104,
116,
116,
112,
115,
58,
47,
47,
116,
111,
107,
101,
110,
45,
109,
101,
116,
97,
100,
97,
116,
97,
46,
112,
97,
120,
111,
115,
46,
99,
111,
109,
47,
112,
121,
117,
115,
100,
95,
109,
101,
116,
97,
100,
97,
116,
97,
47,
112,
114,
111,
100,
47,
115,
111,
108,
97,
110,
97,
47,
112,
121,
117,
115,
100,
95,
109,
101,
116,
97,
100,
97,
116,
97,
46,
106,
115,
111,
110,
0,
0,
0,
0
]
}
}
Fetch Metaplex Token Metadata
For tokens using the Metaplex Token Metadata Program, you can fetch the metadata account to get the token’s name, symbol, and URI. The Kit examples use the Metaplex Token Metadata client. Install it together with@solana-program/token, which the client loads but doesn’t declare as a
dependency:
npm install @solana/kit @metaplex-foundation/mpl-token-metadata-kit @solana-program/token
@metaplex-foundation/mpl-token-metadata-kit 0.0.3 is built on Kit 6. It
runs with Kit 8, but TypeScript reports the RPC types as incompatible until
you resolve it onto your Kit version in package.json, then delete
node_modules and package-lock.json and run npm install again:"overrides": {
"@metaplex-foundation/mpl-token-metadata-kit": {
"@solana/kit": "$@solana/kit",
"@solana/program-client-core": "^8.6.0"
}
}
import { address, createSolanaRpc } from "@solana/kit";
import { fetchMetadataFromSeeds } from "@metaplex-foundation/mpl-token-metadata-kit";
const rpc = createSolanaRpc("http://localhost:8899");
// Example: USDC mint address
const mintAddress = address("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
// Fetch metadata directly using the mint address
const metadata = await fetchMetadataFromSeeds(rpc, { mint: mintAddress });
console.log("Token Name:", metadata.data.name);
console.log("Token Symbol:", metadata.data.symbol);
console.log("Metadata URI:", metadata.data.uri);
console.log("Update Authority:", metadata.data.updateAuthority);
import asyncio
import struct
from solana.rpc.async_api import AsyncClient
from solders.pubkey import Pubkey
METADATA_PROGRAM_ID = Pubkey.from_string("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
async def main():
async with AsyncClient("http://localhost:8899") as client:
# Example: USDC mint address
mint = Pubkey.from_string("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
# The metadata account is a PDA derived from the mint address
metadata_address, _ = Pubkey.find_program_address(
[b"metadata", bytes(METADATA_PROGRAM_ID), bytes(mint)], METADATA_PROGRAM_ID
)
data = (await client.get_account_info(metadata_address)).value.data
# Layout: key (1 byte), update authority (32), mint (32), then name, symbol, uri
update_authority = Pubkey.from_bytes(data[1:33])
fields, offset = [], 65
for _ in range(3):
(length,) = struct.unpack_from("<I", data, offset)
fields.append(data[offset + 4 : offset + 4 + length].decode().rstrip("\x00"))
offset += 4 + length
name, symbol, uri = fields
print("Token Name:", name)
print("Token Symbol:", symbol)
print("Metadata URI:", uri)
print("Update Authority:", update_authority)
asyncio.run(main())
package main
import (
"context"
"fmt"
"strings"
bin "github.com/gagliardetto/binary"
"github.com/solana-foundation/solana-go/v2"
"github.com/solana-foundation/solana-go/v2/rpc"
)
func main() {
client := rpc.New("http://localhost:8899")
// Example: USDC mint address
mint := solana.MustPublicKeyFromBase58("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
// The metadata account is a PDA derived from the mint address
metadataAddress, _, err := solana.FindTokenMetadataAddress(mint)
if err != nil {
panic(err)
}
account, err := client.GetAccountInfo(context.Background(), metadataAddress)
if err != nil {
panic(err)
}
// The first fields of the Metaplex Metadata account
var metadata struct {
Key uint8
UpdateAuthority solana.PublicKey
Mint solana.PublicKey
Name string
Symbol string
Uri string
}
if err := bin.NewBorshDecoder(account.GetBinary()).Decode(&metadata); err != nil {
panic(err)
}
fmt.Println("Token Name:", strings.TrimRight(metadata.Name, "\x00"))
fmt.Println("Token Symbol:", strings.TrimRight(metadata.Symbol, "\x00"))
fmt.Println("Metadata URI:", strings.TrimRight(metadata.Uri, "\x00"))
fmt.Println("Update Authority:", metadata.UpdateAuthority)
}
Not all tokens have Metaplex metadata. Tokens created with Token Extensions
(Token-2022) may use the different functionality instead. See Token
Extensions Metadata for more information.