0

I am trying to decode the metadata account data for an NFT in a react app. The metaplex SDK makes use of the connection object, which is fine for public nodes, but my front end connects to my quicknode end point via a backend so that the actual address of the endpoint is hidden from users.

Is there any way to access the metaplex account data via a curl/get request directly, or alternatively, does anyone know how to decode the metadata using borsh directly following a simple getAccountData request?

My attempt at using getAccountInfo using the following approach has so far failed with the error Error: Expected buffer length 73237764 isn't within bounds

const creator_scheme = new Map([
    [NFT_Creator, { kind: 'struct', 
    fields: [
        ["address", [32]],
        ["verified", "u8"],
        ["share", "u8"],
        ],
      }]
]);

const collection_scheme = new Map([
    [NFT_Collection, { kind: 'struct', 
    fields: [
        ["verified", "u8"],
        ["key", [32]]
        ],
      }]
]);

const uses_scheme = new Map([
    [NFT_Uses, { kind: 'struct', 
    fields: [
        ["use_method", "u8"],
        ["remaining", "u64"],
        ["total", "u64"],
        ],
      }]
]);


const metadata_scheme = new Map([
    [NFT_MetaData, { kind: 'struct', 
    fields: [
        ["name", "string"],
        ["symbol", "string"],
        ["uri", "string"],
        ["sellerFeeBasisPoints", "u16"],
        ["creators", { kind: "option", type: [creator_scheme] }],
        ["collection", { kind: "option", type: [collection_scheme] }],
        ["uses", { kind: "option", type: [uses_scheme] }],
        ],
      }]
]);

Many Thanks

1 Answer 1

1

You certainly can fetch data with just curl, ie:

curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getAccountInfo",
    "params": [
      "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
      {
        "encoding": "base64"
      }
    ]
  }
'

As for decoding the returned data, it looks like you have it mostly correct. You can compare how your types are defined vs the types in the official JS package, or simply use that directly, ie:

import { Metadata } from '@metaplex-foundation/mpl-token-metadata';
const buf = ... // buffer with account data bytes
Metadata.deserialize(buf)

More info at https://github.com/metaplex-foundation/metaplex-program-library/blob/b8735d98ad592ea5847631435ceff5d9b2881a01/token-metadata/js/src/generated/accounts/Metadata.ts#L87

1
  • Hero.. Metadata.deserialize() was exactly what I was after
    – daoplays
    Feb 8, 2023 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.