0

Is it possible to pack a javascript object with specific types for its properties that can be unpacked in a smart contract (for example Bytes.unpack in ligo)?

enter image description here

I've come to the same point as the example above, but when I try to pack an object instead of the single address mentioned above I get stuck.We need to pack offchain and be able to extract some of these values in a smart contract.Ie: In JS:

{
  address: 'tz1...',
  timestamp: '...',
}

This gets packed and sent as a param to the SC. In SC we unpack as address and timestamp.

Question from Dev Slack.

1 Answer 1

0

This is a minimum example. It’ll require both @taquito/michelson-encode and @taquito/michel-codec packages. And Michelson type [![pair][1]][1] seems fit your use case. It converts Michelson-js-abstraction to Json-Michelson then packed to bytes and unpacked back to Json-Michelson back to Michelson-js-abstraction. The example also show the nuances between packDataBytes and packData for you to choose from.

enter image description here

Here are a list of documentation for your reference:

https://tezostaquito.io/docs/16.2.0/contract_call_parameters#pair

https://github.com/ecadlabs/taquito/tree/master/packages/taquito-michelson-encoder#taquito-michelson-encoder-package

https://github.com/ecadlabs/taquito/tree/master/packages/taquito-michel-codec#pack-michelson-data

Answer from Dev Slack from Hui-An Yang

Your Answer

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