Get example contract

We have prepared a very simple contract that contains only two files: config.yaml with protocol.proto

config.yaml

Define the contract name, version number, and several files that the contract depends on. Here we have only one data structure definition file.

protocol.proto

Define the data structures and new transaction types that will be used in the contract.

The above code has been placed on GitHub, and the acquisition method is relatively simple:

Prepare the compilation environment

TODO: There should be a few additional tools installed here

Compile contract file

Then execute directly forge contract:compile ./protocolAnd get the following output:

If this is the first time forge contract:compile, Forge CLI will automatically download the contract compilation tool forge-compiler

current contract:compile Can produce can give Forge Elixir SDK with Forge JS SDK The files used also produce result files that can be used directly for deployment to chain nodes.

Deployment contract

If you want to execute the contract directly: forge protocol:deploy .compiled/create_product/elixir/create_product/create_product.itx.jsonAnd the result is as follows:

Contracts with the same name and the same version are not allowed to be deployed repeatedly, so if the contract code changes, you need to increment the version number, recompile, and then deploy.

Verify deployment results

carried out forge contract:ls | grep create_productIf you can see the results, the deployment is normal.

Use compiled code

In wangshijun/forge-product-factory-contract Examples of how to use compiled code in the Forge JS SDK: