4

I'm having some issue with the contract read, i have data in format of sp.TMap(string,bytes), im using sp.pack() to get the bytes representation of a sp.TNat in a concrete example for a nat 200 y get as result 05008803, i been trying to decode the data using @TezosTaquito but couldn't get the result expected.

Also trying to replicate the encode of that nat @TezosTaquito don't give me the same bytes gotten from contract.

Using Tzip12 module neither work as expected.

1 Answer 1

3

For packing and unpacking michelson values, you can use the @taquito/michel-codec package.

Example:

const { packDataBytes, unpackDataBytes } = require("@taquito/michel-codec");

export function unpackData(bytes, type) {
  return unpackDataBytes({ bytes }, type);
}

export function packData(value, type) {
  return packDataBytes(value, type).bytes;
}

// Packing
packData({ int: 200 }, { prim: 'nat' }) // 05008803

// Unpacking
unpackData("05008803", { prim: "nat" }) // {"int":"200"}

Live example: https://codesandbox.io/s/elastic-cray-e8oviv?file=/src/index.js

3
  • 1
    Niceeee, 2nd time you save me bro, thanks very much for the help, if you are on NFT move i would like to gift you a piece of our up coming collection. You can contact me on twitter @M88ache. Thanks again Jul 25 at 21:42
  • No need, just accept the answer if it helped you. Jul 26 at 16:32
  • 1
    @MarceloDavidMoisés the best gifts on this stack exchange are green ticks and blue triangles ;)
    – 0x10
    Jul 27 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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