Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to deserialize token metadata #169

Open
DanielSolomon opened this issue Jun 9, 2024 · 3 comments
Open

Failing to deserialize token metadata #169

DanielSolomon opened this issue Jun 9, 2024 · 3 comments

Comments

@DanielSolomon
Copy link

Hey,

I'm trying to deserialize USDC token metadata, using MetadataDeserialize but I get an error: failed to deserialize data, err: failed to read required bytes.

Steps to reproduce:

  • I'm using blocto/solana-go-sdk v1.30.0.
curl https://api.mainnet-beta.solana.com \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc": "2.0","id": 1,"method": "getAccountInfo","params": ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",{"commitment":"finalized","encoding":"base64"}]}'

returns:

{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "1.18.15",
      "slot": 270836536
    },
    "value": {
      "data": [
        "AQAAABzjWe1aAS4E+hQrnHUaHF6Hz9CgFhuchf/TG3jN/Nj22vN7gPIQCQAGAQEAAAAqnl7btTwEZ5CY/3sSZRcUQ0/AjFYqmjuGEQXmctQicw==",
        "base64"
      ],
      "executable": false,
      "lamports": 310700925773,
      "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
      "rentEpoch": 18446744073709552000,
      "space": 82
    }
  },
  "id": 1
}

Using result.value.data run the following test:

package main

import (
	"encoding/base64"
	"testing"

	tokenMetadata "github.com/blocto/solana-go-sdk/program/metaplex/token_metadata"
	"github.com/stretchr/testify/require"
)

func TestMetadataDeserialize(t *testing.T) {
	usdc := "AQAAABzjWe1aAS4E+hQrnHUaHF6Hz9CgFhuchf/TG3jN/Nj2IoXC/PIQCQAGAQEAAAAqnl7btTwEZ5CY/3sSZRcUQ0/AjFYqmjuGEQXmctQicw=="
	data, err := base64.StdEncoding.DecodeString(usdc)
	require.NoError(t, err)
	_, err = tokenMetadata.MetadataDeserialize(data)
	require.NoError(t, err)
}
@yihau
Copy link
Collaborator

yihau commented Jun 10, 2024

EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v is a mint account. you should use this one to parse it: https://blocto.github.io/solana-go-sdk/tour/get-mint.html

@DanielSolomon
Copy link
Author

Thx @yihau.
Is it new? I recently upgraded to v1.30.0 and I'm pretty sure MetadataDeserialize worked for me on mint addresses in an older version.

@yihau
Copy link
Collaborator

yihau commented Jun 10, 2024

MetadataDeserialize should only work for metadata account data. do you remember what the address is, by any chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants