Converts and validates Michelson expressions between JSON-based Michelson and Micheline

Pretty Print a Michelson Smart Contract:

const contract = await Tezos.contract.at("KT1Vsw3kh9638gqWoHTjvHCoHLPKvCbMVbCg");
const p = new Parser();

const michelsonCode = p.parseJSON(contract.script.code);
const storage = p.parseJSON(contract.script.storage);

console.log("Pretty print Michelson smart contract:");
console.log(emitMicheline(michelsonCode, {indent:" ", newline: "\n",}));

console.log("Pretty print Storage:");
console.log(emitMicheline(storage, {indent:" ", newline: "\n",}));

Encode a Michelson expression for initial storage of a smart contract

const src = `(Pair (Pair { Elt 1
(Pair (Pair "tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")
0x0501000000026869) }
10000000)
(Pair 2 333))`;

const p = new Parser();

const exp = p.parseMichelineExpression(src);
console.log(JSON.stringify(exp));

Constructors

Methods

  • Parse a Micheline sequence expression. Enclosing curly brackets may be omitted. An alias for parseList

    Parameters

    • src: string

      A Michelson list expression such as (Pair {Elt "0" 0} 0) or Pair {Elt "0" 0} 0

    Returns null | Expr

    An AST node or null for empty document.

  • Parse a Micheline sequence expression. Enclosing curly brackets may be omitted.

    Parameters

    • src: string

      A Michelson list expression such as (Pair {Elt "0" 0} 0) or Pair {Elt "0" 0} 0

    Returns null | Expr

    An AST node or null for empty document.

  • Parse any Michelson expression

    Parameters

    • src: string

      A Michelson expression such as (Pair {Elt "0" 0} 0) or {parameter ...; storage int; code { DUP ; ...};}

    Returns null | Expr

    An AST node or null for empty document.

  • Parse a Micheline sequence expression, such as smart contract source. Enclosing curly brackets may be omitted. An alias for parseSequence

    Parameters

    • src: string

      A Micheline sequence {parameter ...; storage int; code { DUP ; ...};} or parameter ...; storage int; code { DUP ; ...};

    Returns null | Expr[]

  • Parses a Micheline sequence expression, such as smart contract source. Enclosing curly brackets may be omitted.

    Parameters

    • src: string

      A Micheline sequence {parameter ...; storage int; code { DUP ; ...};} or parameter ...; storage int; code { DUP ; ...};

    Returns null | Expr[]