OCaml SDK

Let's generate a OCaml SDK for KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of and interact with it. See section SDK generation for the details about this contract. The OCaml SDK relies on the tzfunc library for forging and signing operations.

Import a KT1 from the Tezos blockchain

To generate the SDK of the contract in the current directory, run:

factori import kt1 . KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of \
    --ocaml \
    --name my_contract \
    --network ghostnet \
    --force

Compile dependencies

You want to install the necessary OCaml dependencies. You need to be inside an opam switch, or you can create one with

make _opam

Then install needed dependencies:

opam update
make deps

Now cleanly format the generated code:

make format-ocaml

You are ready to use the OCaml SDK!

Hello world example

First, you may want to have a look at the content of src/ocaml_sdk/ and src/ocaml_scenarios/ directories:

tree src/ocaml_sdk/ src/ocaml_scenarios/

Edit the file src/ocaml_scenarios/scenario.ml with the following content:

module M = My_contract_ocaml_interface
module B = Blockchain

let main () =
  let open Tzfunc.Rp in
  let hello_kt1 = "KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of" in
  let>? oph =
    M.call_hello
      ~from:B.alice_flextesa
      ~kt1:hello_kt1
      ~node:B.ghostnet_node
      "Hello from OCaml"
  in
  Format.eprintf "A hello operation was sent to the node, with hash %s@." oph ;
  Format.eprintf
    "Check the status of your operation: https://ghostnet.tzkt.io/%s@."
    oph ;
  Lwt.return_ok oph

let _ = Tzfunc.Node.set_silent true

let _ = Lwt_main.run @@ main ()

To run it, simply run:

make run_scenario_ocaml

If everything goes well, you should see your transaction at: https://ghostnet.tzkt.io/KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of

Quick Deploy

If you want to quickly re-originate the contract, you can run

factori deploy --ocaml --network ghostnet --storage blockchain my_contract

This will deploy the contract on Ghostnet, using Flextesa's Alice account, and with as initial storage the storage on the blockchain at the moment of importation.