0

how can I transfer micheline code to michelson code?

I'm writing a lambda in michelson code that take some user's inputs. I can present it to user in michelson code for double check. but when the lambda is stored onchain storage and I get it back, it becomes micheline code in json. I'm wondering if I can change it back to in michelson code?

2 Answers 2

0

Use @taquito/michel-codec

import { Parser } from '@taquito/michel-codec'

const example = async () => {

  try {
    // Encode initial storage values to JSON that is acceptable to the Tezos RPC
    const ex1 = '(Pair {Elt "0" 0} 0)'
    const ex2 = `(Pair (Pair { Elt 1
                  (Pair (Pair "tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")
                        0x0501000000026869) }
            10000000)
      (Pair 2 333))`;

    const p = new Parser()

    console.log('Example 1')
    const exp1 = p.parseMichelineExpression(ex1)
    console.log(JSON.stringify(exp1))

    console.log('Example 2')
    const exp2 = p.parseMichelineExpression(ex2)
    console.log(JSON.stringify(exp2))

  } catch (ex) {
    console.log(ex)
  }
}

example();

https://github.com/ecadlabs/taquito/blob/master/example/encode-michelson.ts

0

There is a Parser class in @taquito-michel-codec with parseJSON method that can do that. This is an example https://github.com/ecadlabs/taquito/blob/master/packages/taquito-michel-codec/README.md#pretty-print-a-michelson-contract

Your Answer

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