Compiling contracts
You must compile LIGO contracts to Michelson before deploying them. LIGO can also help you compile the initial storage value for a contract and parameters for calls to contracts.
Compiling contracts
To compile a LIGO contract, make sure that LIGO is installed as described in Installation.
Then, pass the source file to the ligo compile contract
command.
For example, this command compiles a contract that is at the root level of a source file named my_contract.jsligo
and writes it to the file my_contract.tz
:
If the contract is in a module, pass the name of the module to the -m
argument, as in this example:
Now you can deploy (originate) the contract; see Deploying contracts.
For more information about the ligo compile contract
command, see compile contract
.
The ligo compile contract
command does not automatically run tests in the source file.
To run tests, use the ligo run test
command as described in Testing.
Compiling storage
When you originate a contract, you set the initial value of the contract storage as a Michelson value.
The ligo compile storage
command compiles LIGO expressions to Michelson expressions that you can use for the initial value of the storage.
For example, this contract has a complex storage type that includes two records and an address:
To compile an initial storage value for this contract, create a JsLIGO expression of the storage type and pass it to the ligo compile storage
command, as in this example:
The result is a Michelson expression that you can use as the initial storage value:
If you deploy a contract with the octez-client originate contract
command, you can pass this expression as the value of the --init
argument, as in this example:
For more information about the ligo compile storage
command, see compile storage
.
Compiling parameters
If you have the source code of a LIGO contract, you can use the ligo compile parameter
command to compile the parameter that another contract or client can use to call it.
For example, this contract has an entrypoint that accepts a complex parameter:
To compile a parameter to call this contract, create a JsLIGO expression for the parameter and pass it and the entrypoint name to the ligo compile parameter
command, as in this example:
The result is a Michelson expression that represents passing the value to the entrypoint:
You can use this expression as the parameter to call the contract, as in this example:
If you deploy a contract with the octez-client originate contract
command, you can pass this expression as the value of the --init
argument, as in this example:
For more information about the ligo compile parameter
command, see compile parameter
.