1

I am trying to deserialize the data on newly created tokens.

For example I am using this transaction (Link To Solscan).

I am trying to use the getCreateMetadataAccountV3InstructionDataSerializer.deserialize method like below

function decodeAndLogData(data) {
    const { getCreateMetadataAccountV3InstructionDataSerializer } = require('@metaplex-foundation/mpl-token-metadata');

    const dataSerializer = getCreateMetadataAccountV3InstructionDataSerializer();
    const decodedData = dataSerializer.deserialize(data);
    return decodedData;
}

If you see the example transaction above you can see there is an instruction for this and you can pull the data off of it.

I have tried to convert it to a UInt8Array, hex, and everything else that I could think of but have not had any luck.

I have also tried to look up the serialization stuff in github but have not been able to figure it out either.

Has anyone had any luck getting the metadata off the initial token creation transaction and if so would you help point me in the correct direction?

1 Answer 1

1

How are you fetching the data? Are you using the web3js library for it? If yes then the data is returned in the bs58-encoded string format. You have to first deserialize it into Uint8Array. You can use the bs58 package for it like this:

import bs58 from 'bs58';

function decodeAndLogData(data) {
    const { getCreateMetadataAccountV3InstructionDataSerializer } = require('@metaplex-foundation/mpl-token-metadata');

    const dataSerializer = getCreateMetadataAccountV3InstructionDataSerializer();
    const decodedData = dataSerializer.deserialize(bs58.decode(data));
    return decodedData;
}

If the above solution doesn't work, I would suggest you to post the input value of the data in the question as well.

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.