gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
884 stars 257 forks source link

Pls help me, how to get token metadata? #190

Closed SyugamCan closed 4 months ago

SyugamCan commented 7 months ago

meta, err := tokenregistry.GetTokenRegistryEntry(context.Background(), client, mintAddress) token: 2bjao38z4hUC1wY5yQiDhRF43TjLoBpyPSQhsikhCBEr and err is "not found" i guess we should interact withMetaplex is there any new func to get meta?

0xvbetsun commented 7 months ago

yes @SyugamCan, you are right. It's better to take a look at this repo

to get at least something you can use the next script

package main

import (
    "context"

    "github.com/davecgh/go-spew/spew"
    "github.com/gagliardetto/solana-go"
    "github.com/gagliardetto/solana-go/programs/token"
    "github.com/gagliardetto/solana-go/rpc"
)

func main() {
    mintKey := solana.MPK("2bjao38z4hUC1wY5yQiDhRF43TjLoBpyPSQhsikhCBEr")

    client := rpc.New(rpc.MainNetBeta.RPC)

    var mint token.Mint
    client.GetAccountDataInto(context.TODO(), mintKey, &mint)

    metadataPDA, _, err := solana.FindTokenMetadataAddress(mintKey)
    if err != nil {
        panic(err)
    }

    spew.Dump(mint)
    spew.Dump(metadataPDA)
}

Output:

(token.Mint) {
 MintAuthority: (*solana.PublicKey)(<nil>),
 Supply: (uint64) 999935143218046,
 Decimals: (uint8) 6,
 IsInitialized: (bool) true,
 FreezeAuthority: (*solana.PublicKey)(<nil>)
}
(solana.PublicKey) (len=32 cap=32) GJvLsXpLttda51tBR2bFU3wd8AoJULNgjybwxAkFVUWx