AWS Database Blog

Verify delivery conditions with the Accord Project and Amazon Quantum Ledger Database – Part 1

Smart legal contracts are an emerging technology in the legal tech domain. Their main goal is to make the verification of terms and conditions in legal contracts more efficient. Unlike smart contracts, which are self-running programs in distributed ledger databases (usually in blockchain-based systems), smart legal contracts represent an entire legal contract. They combine a contract’s legal prose with a script that prescribes how the contract needs to react on the actions of contract parties. As a result, by using smart legal contracts, we can reduce costs of tracking the actions of parties bounded by a legal contract and automatically emit obligations based on formal rules specified in the legal contract clauses.

But cost-efficiency isn’t the only advantage of using smart legal contracts. Combined with immutable and tamper-resistant digital ledgers, they can elevate the level of trust between parties and, therefore, speed up the run of processes established between them. This technology is especially useful in cases when those processes are already governed by repeatable and templatized legal contracts.

One of the software development initiatives that implements this technology is the Accord Project. It’s an open-source initiative for developing a full technical framework to create, manage, and run smart legal contracts. Tools provided by the Accord Project are agnostic of the underlying compute and storage layers and can be used with a variety of digital ledgers, including decentralized and centralized options. This level of flexibility allows you to focus on solving a business problem first and choosing the underlying implementation later, based on changing needs. For example, you can choose to start with a more convenient centralized database technology and move to a decentralized distributed ledger network when the need for the decentralization becomes clear.

To create a smart legal contract with the Accord Project, we use one or more contract templates and initialize them with the details of the legal contract. Templates encapsulate a templatized legal prose tightly coupled to a common data model with scripts that implement a machine-runnable contract logic. To instantiate and run the logic from a template, the Accord Project provides the Cicero templating system, with an embedded engine to run scripts written in Ergo language and implemented in JavaScript. Such implementation makes the code highly portable and allows you to run smart legal contracts inside JavaScript virtual machines within web browsers or with Node.js on a server.

Some difficulties are also associated with this technology. Because both the smart legal contract and the final decisions it makes can become sources of disputes, we should keep them in a way that guarantees full data integrity, independent of the will of parties involved. As of this writing, two services on AWS can do it: Amazon Managed Blockchain and Amazon Quantum Ledger Database (Amazon QLDB). Both services achieve data integrity through cryptography by making the data impossible to edit without leaving a trace. The difference is that with Managed Blockchain, data is copied between nodes managed by independent AWS accounts, and Amazon QLDB is a centralized ledger database with data stored for a single AWS account.

In this series of two posts, we focus on implementing a smart legal contract for the delivery of goods between a buyer and a seller that are well known to each other. An important condition for applying smart legal contracts technology is that we assume the delivery process between our parties is well established and is governed by a template-based delivery contract. For such repeatable deliveries, the contract specifies the way a penalty is calculated based on the details of a delivery event and automatically issues a payment obligation for a seller or triggers the contract termination on behalf of a buyer. With this approach, we can significantly reduce the costs of verification of delivery conditions. The smart legal contract automatically emits obligation events directly associated with the specific contract clause that lets other systems react to those events and take appropriate actions.

Process overview

Let’s imagine a scenario in which a coffee shop has a contract with a wholesaler of dairy products to deliver milk every 7 days on a pre-paid basis. This is beneficial for the coffee shop because it can keep a limited supply of milk for their coffee and save on expensive storage space rentals at a shopping mall. We use a contract template to create a contract and specify the names of the coffee shop and the dairy products wholesaler, the amount of a penalty (10.5% of the total cost of milk delivery per 2 days of delay, capped at 52.0% of a total delivery value), and a clause to automatically end the contract after 15 days of delay. After the contract template is initialized with those values, we have a full smart legal contract in place. The manager of the coffee shop can use the functions of that smart legal contract to check in every delivery with both pre-agreed and actual delivery dates as well as the value of the milk delivered. That triggers the contract logic from the contract template, which either emits a payment obligation event to charge the wholesaler a penalty, or completely halts this particular delivery after 15 days of delay. Let’s see how we can implement this on AWS.

Solution overview

First of all, we want to make sure our solution is cost-effective. We don’t expect high frequency of incoming events and we don’t plan to process large amounts of data. Therefore, it’s not necessary to reserve long-running compute resources, so we use serverless services as much as possible. This brings us to the solution architecture depicted in the following diagram.

The diagram contains the following elements:

  1. The runtime for the smart legal contracts .
  2. The catalog of contract templates.
  3. An immutable storage with cryptographic verification to keep the smart legal contracts.
  4. A queueing service to emit contract obligations.
  5. Systems that pick up and process contract obligations.

The user systems depicted in the diagram can be either one of the AWS services or your own custom application that can invoke an AWS Lambda function with the AWS SDK. For more information, see Invoking AWS Lambda functions and Using AWS Lambda with other services. Let’s take a closer look at our choice of services:

  • AWS Lambda is a compute service that lets you run code without provisioning or managing servers. Lambda runs your code only when needed and scales automatically, from a few requests per day to thousands per second. We use this service because it’s designed for event-driven applications, which is exactly what we need to trigger the logic of smart legal contracts and react to external events. Second, it provides a secure runtime environment, which makes it impossible to interfere with the logic of our contract during its run. Third, although currently beyond of the scope of this post, with Lambda we can make a compute component of our solution fully auditable using the code signing feature and log function invocations as data events with AWS CloudTrail, which helps to build trust into our system.
  • Amazon QLDB is a fully-managed ledger database that provides a transparent, immutable, and cryptographically verifiable transaction log. It’s a good choice for us because it gives us cryptography-based data integrity guarantees without the complexity of similar systems based on blockchain or other distributed ledger technologies. Its immutable ledger also allows us to easily retrieve the full history of events submitted to our contract and all the outputs produced as reactions on those events. In addition, we can use a Zero Trust architectural approach to elevate trust in the business relationships of contract parties by sharing read-only access to the ledger when needed. We can do it with AWS Identity and Access Management (IAM) cross-account access features and restrict actions to read-only operations like GetBlock, GetDigest, and GetRevision, which are necessary to do an audit of data integrity. Calls to these operations are also logged in CloudTrail.
  • AWS Simple Storage Service (Amazon S3) is great for storing objects like files. In our solution, Amazon S3 stores the Accord Project’s contract template archives (.cta) files, essentially making it a repository of all templates that can be initialized and instantiated in our system. With capabilities like versioning and object locking, we can easily extend Amazon S3 to serve different requirements, including regulatory and compliance. We also put hashes of the .cta files into Amazon QLDB and check it every time we run the logic of our contract to make sure it hasn’t been changed.
  • Amazon Simple Queue Service (Amazon SQS) helps integrate and decouple components of a distributed system. In our use case, Amazon SQS receives events emitted by the contract and lets other components, for example an accounting system, react to them and automatically start a penalty payment approval process for a payment obligation event.


In this part of the series, we introduced the smart legal contract technology and its implementation in the open-source initiative called the Accord Project. We also introduced a sample delivery process and reviewed the solution to run smart legal contracts on AWS. In the next part we will dive deeper into the details of the solution and review the key functions including the instantiation, running and verification of the sample smart legal contract.

The example discussed in this part is just one of the ways to use smart legal contracts technology. You can apply it in many other domains, from managing letters of credit in financial services to tracking maintenance contract activities for heavy machinery in the industrial sector. For more inspiration, check out the many other examples in the Accord Project Template Library.

In the next part of this series we will dive deep into how the solution works.

About the author

Nikolay Vlasov is a Senior Blockchain Architect with AWS Professional Services. Being part of a Global Speciality Practice team, he helps clients worldwide to turn their ideas into Pilots, Minimally Viable Products, and Production-ready systems based on blockchain technology.