1

How can I pretty-print a Michelson contract in JSON to concrete syntax?

1
  • 1
    This is done by the SmartPy.io/dev explorer. We could extract the code if you need it or integrate it in the CLI.
    – FFF
    Mar 6 '20 at 2:45
1

With PyTezos it would be (don't mind the naming, it is wrong, will be fixed at some point):

>>> from pytezos.michelson.converter import micheline_to_michelson
>>> print(micheline_to_michelson({'prim': 'pair', 'args': [{'string': 'hello'}, {'int': '42'}]}))
pair "hello" 42
1

Edit: I realized that I misread the question and answered it for Michelson to Micheline when you wanted Micheline to Michelon. I do not know if there is a way to do that via the command line. Regardless, it would be nice to have both supported by the tezos-client tool.

Michelson to Micheline

It would be nice if there was a dedicated tezos-client command to do this, but as far as I know there is not. This is what I usually do.

tezos-client -l typecheck script michelson.tz > micheline.json 2>&1

There will be some none json details in micheline.json that need to be removed.

This is an even bigger problem if you want to translate a lambda in Michelson to Micheline to use it in a Tezos library that only knows how to handle JSON. My current work around is to dry run the lambda in the contract that is going to use it.

tezos-client transfer 0 from alice to aliceLimit --entrypoint 'do' --arg '{DROP; PUSH address "KT1HWN9KL97fo7oYZgy36Je7ZYZAY6Xt4ye2"; CONTRACT %transfer (pair (pair address address) nat); IF_SOME {PUSH mutez 0; PUSH nat 100; PUSH address "tz1boB5GrcAVRtjQQLrpjM4Xpp1E438La4Wn"; PUSH address "KT1Etn69GyqDCAhZp7wY21s4Y8HefH2ujrSf"; PAIR; PAIR; TRANSFER_TOKENS;} {PUSH string ""; FAILWITH;}}' --dry-run > lambda.json 2>&1

If it succeeds you can delete the extra details from the file. There will be a lot of other unrelated things in there.

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.