Closed seajmurphy closed 2 years ago
This SDK haven't support GetTokenAccountsByOwner
yet but I think getProgramAccounts
can do the same thing like
package main
import (
"context"
"fmt"
"log"
"github.com/portto/solana-go-sdk/client"
"github.com/portto/solana-go-sdk/client/rpc"
"github.com/portto/solana-go-sdk/common"
)
func main() {
c := client.NewClient(rpc.DevnetRPCEndpoint)
res, err := c.GetProgramAccountsWithConfig(
context.Background(),
common.TokenProgramID.ToBase58(),
rpc.GetProgramAccountsConfig{
Encoding: rpc.GetProgramAccountsConfigEncodingJsonParsed,
Filters: []rpc.GetProgramAccountsConfigFilter{
{
DataSize: 165,
},
{
MemCmp: &rpc.GetProgramAccountsConfigFilterMemCmp{
Offset: 32,
Bytes: "your owner base58 address here",
},
},
},
},
)
if err != nil {
log.Fatalf("failed to get program accounts, err: %v", err)
}
fmt.Println(res.Result)
}
Recently I'm refactoring rpc. It will be supported soon!
thank you for the quick response @yihau 😃
I've add it in ~v2.0.0~ => v1.9.0 . I will do some mapping in the wrapped client for more convenient usage.
Could be wrong about this, but it looks like there is no RPC call available on the client for
GetTokenAccountsByOwner
. From my experience so far working with NFTs, if you want to get Metaplex data for NFTs in a wallet, you must useGetTokenAccountsByOwner
RPC to first retrieve the mint address. Conveniently this package does handle getting and parsing Metaplex data, so perhaps there is a gap in my understanding? Otherwise, I could take a shot at creating a PR for this.