Connecting Legal Contracts to Physical Devices

Clause
Clause
Published in
5 min readDec 2, 2018

Clause’s tag line is “Connected Contracting” and in this article I’m going to show you how to put that into practice, with no programming... Ok, I did create a Cicero template, so you don’t have to!

I will walk you through how you can create a Smart Legal Contract running on the Clause platform and connect it to a programmable button from Flic and have the button trigger a Smart Clause within your legal contract.

This is a nice example of a fairly sophisticated contract that has state (memory) and that responds to 4 different messages from the outside world and sends notifications using email.

The Flic button

The Flic programmable button.

The Flic button is a cute little programmable button. It connects to your phone (or the Flic hub) over Bluetooth and you can press it, double press it, or long-press it. Each action is programmable through the easy to use Flic app on your phone. We will configure the button to trigger a Smart Clause running on the Clause platform for each of the button press types.

Note that other similar devices are available. For example, if you prefer a WiFi connected button the AWS IoT Button may be a good (albeit, more complex to setup) choice.

The Template

I’ve created an Accord Project template for the Smart Clause we will be using. The template defines the legal prose, data model and logic that we require.

Accord Project Cicero Template

The template is stateful (it has a memory!) and it uses a counter to keeps track of the number of times a connected button has been clicked. Each time the button is single-clicked the template increments the counter. Each time the button is double-clicked the counter is decremented. When the button is long-pressed the contract emits a payment obligation indicating how much the buyer owes the seller, calculated based on the counter and a unit price per click.

In addition you can send payment notifications to the template to indicate that payment has been received and the template will decrement the counter based on the amount received and the unit price. After a contractually specified number of payments have been received the contract moves to the COMPLETED state and shuts down.

Ergo logic to handle a payment

The Smart Legal Contract

After importing the template into your template library you can create a new contract and add the Smart Clause to your contract and configure it with the desired values. I’m not a lawyer, so take the legal prose with a pinch of salt! The beauty of Cicero templates is that the legal prose can be modified without changing the data model or the logic.

Adding the Smart Clause to a contract

You should also configure the Actions for the Smart Clause to send an email message when a Payment Obligation is emitted.

Configure a custom email action for the Smart Clause

We use a custom email action so that the amount emitted by the Smart Clause appears in the email that is automatically sent. The transformation used is included below for reference.

{
“$class”: “io.clause.outbound.physical.alerts.email.EmailMessage”,
“contractId”: “xxxxxxx”,
“to”: “foo@email.com”,
“subject”: “Request for payment”,
“message”:”Amount requested: “ & response.amount.doubleValue & “ “ & response.amount.currencyCode
}

Note the trigger URL and authorization token for the Smart Clause. We will need those to connect the Smart Clause to our button later.

Signing the Smart Legal Contract

Before we can send data to the contract it must be signed. Add a second signatory to your contract and press the Request Signatures button to trigger the signature flow. Once all parties have signed the contract it transitions to the RUNNING state and is ready to receive data.

Configuring your Flic Button

You should now use the Flic App on your phone to configure the 3 actions for your button to send data to the Smart Clause.

Configuring a Flic button to call a Smart Clause

Use the Internet Request action (in the advanced category) and configure the action to make an HTTP POST to the Trigger URL for your Smart Clause. You will need to set the Content-Type to application/json and set a HTTP header with the key Authorization and the value Bearer <SMART_CLAUSE_TOKEN> replacing <SMART_CLAUSE_TOKEN> with the bearer token for your Smart Clause.

The Body of the HTTP POST will vary based on the click type:

Click: {“$class”: “org.accordproject.iot.SingleButtonPress”}

Double-Click: {“$class”: “org.accordproject.iot.DoubleButtonPress”}

Hold: {“$class”: “org.accordproject.iot.LongButtonPress”}

Give it a try!

You should now be able to press your button and see the events being processed by your Smart Clause, appearing in the Timeline.

Smart Clause processing clicks from your Flic button

When you long-press the button you should receive an email indicating how much you owe — based on the number of times you have clicked, or double-clicked, the button.

An email containing an amount dynamically calculated based on the contract terms.

Registering a Payment

To register a payment with the Smart Clause you can send HTTP message programmatically. For example, using the cURL command line application:

curl — request POST \
— url https://api.clause.io/clauses/<CLAUSE_ID>/trigger \
— header ‘authorization: Bearer <BEARER_TOKEN>’ \
— header ‘content-type: application/json’ \
— data ‘{
“$class”: “org.accordproject.payment.iot.MonetaryAmountPayment”,
“amount” : {
“$class” : “org.accordproject.money.MonetaryAmount”,
“doubleValue” : 16.0,
“currencyCode” : “USD”
}
}

In practice you could integrate this call into your accounting system, or build a custom web application to register payments.

After you have made 5 payments (or whatever you specified in the contract!) the Smart Clause will transition to the COMPLETED state and you will no longer be able to interact with it.

Summary

I hope this article has given you a taste for the power and possibilities that connecting your contracts to the real-world via IoT devices can offer.

For example, you could register deliveries, start and stop timers, register departure, arrival, count packages arrived, count number of jobs performed, indicate breakages, send notifications — all in realtime, and have them handled by the logic of a digitized legal contract.

You also benefit from real-time notifications and visibility into the state of all your contracts and all the events that they have processed.

--

--

Clause
Clause
Editor for

The future of legal contracting. This blog has been relocated to https://blog.clause.io/. Our Medium feed will no longer be updated.