/ergo

The Ergo Language for Smart Legal Contracts

Primary LanguageCoqOtherNOASSERTION

Ergo

Build Status CircleCI Coverage Status lerna npm version

https://docs.accordproject.org/docs/ergo

About

This is the source code for the Ergo compiler. Ergo is the Accord Project language for Smart Legal Contracts.

The Ergo compiler is distributed as an npm package. If you want to install Ergo, consult the getting started section.

The Ergo compiler is written in Coq with a parser and some support code written in OCaml. It makes extensive use of the Q*cert compiler for code generation.

Both the Ergo language and its compiler are in early development phase. If you would like to build from source or to contribute, consult the for developers section.

Try it out

If you want to take a peek at Ergo without installing anything, check out the interactive REPL (read-eval-print-loop) for Ergo stand-alone, or the Accord Project Template Studio showing how Ergo can express the logic of legal templates.

Documentation

The most recent documentation for the Ergo language and compiler is available at https://docs.accordproject.org/docs/ergo.html

Getting started

Install Ergo

The easiest way to install Ergo is as a Node.js package. Once you have Node.js installed on your machine, you can get the Ergo compiler and command-line using the Node.js package manager by typing the following in a terminal:

$ npm install -g @accordproject/ergo-cli

This will install the compiler itself (ergoc) and command-line tools (ergorun and ergotop) to create and invoke Ergo contracts. You can check that both have been installed and print the version number by typing the following in a terminal:

$ ergoc --version
$ ergorun --version

Then, to get command line help:

$ ergoc --help
$ ergorun --help

Compiling your first contract

To compile your first Ergo contract to JavaScript:

$ ergoc ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo
15:17:08 - info: Logging initialized. 2018-05-24T19:17:08.024Z
Processing file: ./examples/volumediscount/logic.ergo -- compiled to: ./examples/volumediscount/logic.js

By default, Ergo compiles to JavaScript for execution. You can inspect the compiled JavaScript code in ./examples/volumediscount/logic.js

Invoke a contract

To compile and execute a contract by sending a request:

$ ergorun execute ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --contract ./examples/volumediscount/contract.json --request ./examples/volumediscount/request.json --state ./examples/volumediscount/state.json
06:40:01 - info:
{
  "response": {
    "discountRate": 2.8,
    "$class": "org.accordproject.volumediscount.VolumeDiscountResponse"
  },
  "state": {
    "$class": "org.accordproject.cicero.contract.AccordContractState",
    "stateId": "1"
  },
  "emit": []
}

To compile and invoke a specific contract clause:

$ ergorun invoke ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --clauseName volumediscount --contract ./examples/volumediscount/contract.json --params ./examples/volumediscount/params.json --state ./examples/volumediscount/state.json
06:40:29 - info:
{
  "response": {
    "discountRate": 2.8,
    "$class": "org.accordproject.volumediscount.VolumeDiscountResponse"
  },
  "state": {
    "$class": "org.accordproject.cicero.contract.AccordContractState",
    "stateId": "1"
  },
  "emit": []
}

To compile and obtain the initial state for the contract:

$ ergorun init ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --contract ./examples/volumediscount/contract.json
06:40:29 - info:
{
  "response": null,
  "state": {
    "stateId": "org.accordproject.cicero.contract.AccordContractState#1",
    "$class": "org.accordproject.cicero.contract.AccordContractState"
  },
  "emit": []
}

For developers

We welcome contributions. We encourage contributors to consult the following Guidelines

To setup for development, please consult the Developer Guide

License

Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.

Copyright 2018-2019 Clause, Inc.