Live Contracts
Setup a node and run your first Live Contract.

Installation

Running Live Contracts requires using the LTO Network workflow node.
In these tutorials, we're always using the developer build of the workflow node, which is available as a Docker container.
1
curl "https://raw.githubusercontent.com/ltonetwork/lto-workflow-node/docker-compose.yml" -o docker-compose.yml
2
docker-compose up
Copied!
If you need more help to install Docker and the workflow node, please follow the step-by-step installation guide.
...
JSON screenshot
To check that the node is correctly up visit https://localhost:3000. You'll see a JSON response containing information about the LTO services.

Project directory structure

Create a directory named livecontracts-tutorial.
1
mkdir -p livecontracts-tutorial
2
cd livecontracts-tutorial
Copied!

Creating a scenario

A Live Contract must contain one or more scenarios that describe the process(es) we're automating. We can write a scenario in either JSON or YAML.
Create file scenario.yml (or scenario.json) in the basic directory.
YAML
JSON
1
$schema: "https://specs.livecontracts.io/v0.2.0/scenario/schema.json#"
2
title: The basics
Copied!
1
{
2
"$schema": "https://specs.livecontracts.io/v0.2.0/scenario/schema.json#",
3
"title": "The basics"
4
}
Copied!

Defining actors

Actors are organizations or individuals that play a role in the process. The scenario needs to define which actors (may) exist.
YAML
JSON
1
$schema: "https://specs.livecontracts.io/v0.2.0/scenario/schema.json#"
2
title: The basics
3
4
actors:
5
initiator:
6
title: Initiator
Copied!
1
{
2
"$schema": "https://specs.livecontracts.io/v0.2.0/scenario/schema.json#",
3
"title": "The basics",
4
"actors": {
5
"initiator": {
6
"title": "Initiator"
7
}
8
}
9
}
Copied!
We've defined a single actor for the process; the initiator. Normally a process contains 2 or more actors.
The key initiator is used to reference the actor. The title must be defined, but only exists for displaying purposes.

Defining actions

All actions that any actor can perform within the process must be defined at forehand in the scenario.
YAML
JSON
1
$schema: "https://specs.livecontracts.io/v0.2.0/scenario/schema.json#"
2
title: My first Live Contract
3
4
actors:
5
initiator:
6
title: Initiator
7
8
actions:
9
complete:
10
title: Complete the process
11
actor: initiator
Copied!
1
{
2
"$schema": "https://specs.livecontracts.io/v0.2.0/scenario/schema.json#",
3
"title": "The basics",
4
"actors": {
5
"initiator": {
6
"title": "Initiator"
7
}
8
},
9
"actions": {
10
"complete": {
11
"title": "Complete the process",
12
"actor": "initiator"
13
}
14
}
15
}
Copied!
The complete action can be performed by the initiator actor. The intend of this action is to complete the process. However, that transition needs to be defined in the state.

The initial state

When a process is started, it's in the initial state. From this state it can transition to other states, until the process is completed.
YAML
JSON
1
$schema: "https://specs.livecontracts.io/v0.2.0/scenario/schema.json#"
2
title: My first Live Contract
3
4
actors:
5
initiator:
6
title: Initiator
7
8
actions:
9
complete:
10
title: Complete the process
11
actor: initiator
12
13
states:
14
initial:
15
action: complete
16
transition: :success
Copied!
1
{
2
"$schema": "https://specs.livecontracts.io/v0.2.0/scenario/schema.json#",
3
"title": "Basic user",
4
"actors": {
5
"initiator": {
6
"title": "Initiator"
7
}
8
},
9
"actions": {
10
"complete": {
11
"title": "Complete the process",
12
"actor": "initiator"
13
}
14
},
15
"states": {
16
"initial": {
17
"action": "complete",
18
"transition": ":success"
19
}
20
}
21
}
Copied!
While in the initial state, only the complete action can be performed. Once the action is performed, the process will transition to the :success end state, meaning the process has been completed successfully.

Running a test

To ensure the Live Contract behaves as expected, we need to create and run tests. Tests must be defined using the Gherkin syntax. The Live Contracts test suite that comes with the full node, defines the steps that can be used in the test.
Create file main.feature in the basic directory.
main.feature
1
Feature: Run a simple process that is completed in one step
2
3
Background:
4
Given a chain is created by "Joe"
5
Given "Joe" creates the "main" process using the "basic" scenario
6
And "Joe" is the "initiator" actor of the "main" process
7
8
Scenario:
9
When "Joe" runs the "complete" action of the "main" process
10
Then the "main" process is completed
Copied!
We have a single identity named "Joe". The name is arbitrary but used to keep the identities apart.
Joe initializes the Live Contract by creating a new chain and using our basic scenario. The process name "main" is also arbitrary and used to reference a specific process. It's possible to run multiple processes for a Live Contract, but in our case, only a single process exists.
We need to specify which role Joe is going to have in the process. In this case, he's the initiator of the process.
In the Scenario section (this is unrelated to the workflow scenario), we state that will Joe performs the complete action. As defined in our workflow scenario, the process should transition from initial to :success, which means the process has been completed successfully.

Running the Live contract tester

lctest is a command-line tool to test workflows described in a Live Contract. It can be run from the ltonetwork/letsflow-test docker container.
1
docker run ltonetwork/letsflow-test basic
Copied!
The test should succeed, giving the following output:

Congratulations!

You've successfully created and tested your first Live Contract.

Continue

For more workflow tutorials visit LetsFlow.
Last modified 6mo ago