Add FindTokenMetadataAddress()
Adds a utility function that returns the token metadata program-derived account given a SPL token mint address. Signed-off-by: Richard Patel <richard@blockdaemon.com>
This commit is contained in:
parent
dce349ee7e
commit
4025a4c565
10
keys.go
10
keys.go
|
@ -355,3 +355,13 @@ func findAssociatedTokenAddressAndBumpSeed(
|
|||
programID,
|
||||
)
|
||||
}
|
||||
|
||||
// FindTokenMetadataAddress returns the token metadata program-derived address given a SPL token mint address.
|
||||
func FindTokenMetadataAddress(mint PublicKey) (PublicKey, uint8, error) {
|
||||
seed := [][]byte{
|
||||
[]byte("metadata"),
|
||||
TokenMetadataProgramID[:],
|
||||
mint[:],
|
||||
}
|
||||
return FindProgramAddress(seed, TokenMetadataProgramID)
|
||||
}
|
||||
|
|
11
keys_test.go
11
keys_test.go
|
@ -260,3 +260,14 @@ func TestFindProgramAddress(t *testing.T) {
|
|||
require.Equal(t, address, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindTokenMetadataAddress(t *testing.T) {
|
||||
// Zuuper Grapes (TOILET)
|
||||
// https://solscan.io/token/77K8mr457qxUSSNSfi4sSj5euP8DyuJJWHAUQVW8QCp3
|
||||
mint := MustPublicKeyFromBase58("77K8mr457qxUSSNSfi4sSj5euP8DyuJJWHAUQVW8QCp3")
|
||||
metadataPDA, bumpSeed, err := FindTokenMetadataAddress(mint)
|
||||
require.NoError(t, err)
|
||||
// https://solscan.io/account/GfihrEYCPrvUyrMyMQPdhGEStxa9nKEK2Wfn9iK4AZq2
|
||||
assert.Equal(t, metadataPDA, MustPublicKeyFromBase58("GfihrEYCPrvUyrMyMQPdhGEStxa9nKEK2Wfn9iK4AZq2"))
|
||||
assert.Equal(t, bumpSeed, uint8(0xfd))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue