OCaml

In order to use the OCaml Interface generation feature of Factori, you will need to have opam installed on your machine.

The OCaml SDK can be found in the src/ocaml_sdk subfolder of your Factori project directory.

It is generated by activating the --ocaml option of the factori import kt1 or factori import michelson commands, as seen below:

factori import kt1 <dir> KT1...XXX --network mainnet --name my_contract --ocaml

<dir> is the working directory (it may be relative, such as .), and KT1...XXX is the address of the contract.

will create the directories <dir>/src/ocaml_sdk, <dir>/src/ocaml_scenarios and <dir>/src/libraries. In src, the following files and directories will appear:

  • the src/libraries folder:
    • blockchain.ml: A library for blockchain specific operations;
    • factori_types.ml: A library of types and functions used by all imported interfaces;
    • factory_abstract_types.ml: A library for advanced scenarios;
    • utils.ml: Various utilities.
  • the src/ocaml_sdk folder:
    • my_contract_code.json: the Micheline code of your contract (useful for deployment)
    • my_contract_ocaml_interface.ml: the OCaml interface to your contract, described below.
    • my_contract_abstract_ocaml_interface.ml: the OCaml abstract interface to your contract, only useful for abstract scenarios.
  • the src/ocaml_scenarios folder
    • scenario.ml: an empty scenario file, ready with a dune file with all needed dependencies.

The command also creates a Makefile with useful commands such as:

make format-ocaml

which will format your project.

make format-ocaml

will format the generated code.

make ocaml

will build the code.

make run_scenario_ocaml

will run your scenario.

Description of the interface file

The interface file (my_contract_csharp_interface.ml using the convention from above) consists of both

  1. Types
  2. Functions

The types describe the contract's storage as well as all the input types of the contract's entrypoints (and any intermediate types which may need to be defined in the process). The functions are (mainly) of three kinds:

  1. A deploy function deploy_my_contract;
  2. Calling functions for each entrypoint, of the form call_<entrypoint_name>.
  3. Utility functions for manipulating types, so that in principle, you never have to use Micheline or Michelson directly:
    • Encoding functions from a type to Micheline (<type name>_encode);
    • Decoding functions from Micheline to a type (<type name>_decode);
    • Random generation of elements of the type (<type name>_generator);
    • (technically not a function, but rather a constant): the type itself expressed in Micheline; this is useful e.g. for querying big maps (<type name>_micheline).