Skip to main content

Welcome to Pact

Welcome to the Pact smart contract programming language!

In this tutorial, you’ll learn about Pact, get introduced to its core features, and take your first steps toward becoming a Pact smart contract developer.

Topics covered in this tutorial

  • Introduction to Pact
  • Pact Key Features
  • Learn More About Pact

The goal is to familiarize you with what Pact is, how its used, and some critical decisions that influenced the design of this new language.

Key Takeaway

Pact is the safest, most user-friendly language for smart contracts. It’s designed for security and performance. It is Turing incomplete, human readable, supports upgradable contracts, and formal verification to make high performant and secure smart contracts.

Welcome to Pact Tutorial

Subscribe to our YouTube channel to access the latest Pact tutorials.

Introduction to Pact

Pact is an open-source programming language for writing smart contracts.

It’s designed from the ground up to support the unique challenges of developing solutions to run on a blockchain. Pact empowers developers to create robust and high-performance logic for transactions. It facilitates execution of mission-critical business operations quickly and effectively.

1-pact-smart-contract
1-pact-smart-contract

Pact is designed with safety in mind. Its design is informed by existing approaches to smart contracts as well as stored procedure languages like SQL and LISP. Pact resembles a general-purpose, Turing-complete language. It includes LISP-like syntax, user functions, modules, and imperative style.

Pact Smart Contracts

Pact smart contracts contain three core elements: the code module, keysets, and tables.

The table below briefly introduces each of these core elements.

ModuleA module defines the logic of a smart contract. It contains functions, pact definitions, tables, and schemas.
KeysetsIncludes relevant documentation links and allows you to load code into the REPL, refresh the REPL, or deploy smart contract.
TablesTables store data generated by Pact modules. These tables have a “key-row” structure and support schemas as well as a versioned, columnar history.

Each of these elements support a wide range of functionality. This ensures that you have the tools you need to create robust solutions for real-world problems.

Pact Key Features

There are many valuable features make Pact such a safe and high-performance language. Here are a few that we’ll focus on throughout this tutorial.

Pact Key Features

  • Turing Incomplete
  • Human Readable
  • Upgradable Contracts
  • Formal Verification
  • Type Inference
  • Total Governance
  • RDBMS Integration
  • Pacts

Turing Incomplete

Pact contracts are Turing incomplete.

A Turing complete language has the power to run any possible program. In some languages, Turing completeness is an extremely important feature. For smart contracts, it’s an incredibly dangerous feature. For that reason, Pact is designed to be Turing incomplete which places deliberate constraints on its computational ability. This supports its design goal of “just enough” power for transactional blockchain solutions and helps ensure the security of its smart contracts.

The first restriction in Pact is that there is no unbounded looping or recursion. Pact detects recursion and fails immediately. Looping is also only supported in special circumstances. The key benefits of this are to reduce cost and improve performance. This feature makes some of the most infamous and costly bugs discovered in other platforms not even possible with Pact. For more information on this topic, see our blog post -

Human Readable

Pact smart contracts are human readable.

All Pact code gets stored as written in a human-readable form on the ledger. Pact smart contracts install directly onto the blockchain. This allows you to review the running code as it was written and be sure of exactly what it's doing.

This is important because smart contracts solve business problems that require both technical and non-technical expertise. Building the best smart contract solution requires everyone to understand and contribute to the development of the smart contract.

For that reason, Pact was built to be simple to read and write. This simplicity helps provide complete transparency for the logic within its smart contracts. This approach also encourages shorter programs. The code executes directly on the ledger where it can be read easily by anyone. As a result, Pact is easy to understand.

For example, here’s a “Hello World” smart contract using Pact.

 (module helloWorld 'admin-keyset  (defun hello (name)    (format "Hello {}!" [name])))(hello "world") 
 (module helloWorld 'admin-keyset  (defun hello (name)    (format "Hello {}!" [name])))(hello "world") 

Without having learned anything about the Pact language, you can already start to see how it works. With these few simple lines of code, you see a fully functioning Pact “Hello World” smart contract.

Once written, smart contracts are deployed to a blockchain. In Pact, the code on the blockchain is the same as the code that was written. Maintaining this code means that no matter when you see the code it will always be as it was written. This allows you to understand the code so you can continue to moderate and improve your application over time.

Upgradable Contracts

Pact contracts are upgradable.

Upgradable contracts allow you to revise and improve your smart contracts over time. This allows you to offer new features and fix bugs as you continue developing your smart contract. None of this is possible with other smart contract languages, and it’s a powerful feature when building impactful applications for your business.

Pact's tooling ecosystem further amplifies the simplicity of upgrading contracts. Compiler and runtime errors offer detailed information, with stack traces and function documentation to ensure you’re making the best version of your smart contract.

Pact’s iterative development process is also supported by a feature-rich REPL helping you to improve and deploy new smart contracts rapidly. It includes features such as incremental transaction execution and environment and database inspection.

Formal Verification

Pact comes equipped with a powerful validation tool suite in the form of

formal verification . Pact uses Z3, an open-source tool developed by Microsoft, to mathematically verify and test for bugs present in the code.

This means that Pact allows smart contract authors to express, automatically check, and formally verify that their code does not contain any bugs. Formal verification is the same system used to protect mission-critical environments like nuclear power plants or air and space autopilot systems. You now have this same high level of security in every smart contract you write with Pact.

Formal verification is a huge topic that’s been covered well in the Kadena blog. See the blog post -

Type Inference

Pact includes type inference.

This feature makes it possible for code to be strongly-typed without declaring type information. It also has the added benefit of limiting run-time type enforcement. Developers can use a typecheck to add “just enough types”. Typecheck eliminates warnings and only enforces types at runtime where needed.

Total Governance

Similar to RDBMS systems, Pact offers the benefit of total governance. This benefit allows changes to commit to the database only if the code runs successfully. Any errors roll back changes, abort execution, and avoid costly mistakes.

RDBMS Integration

Pact is also designed to allow direct integration with an industrial RDBMS. This design is helpful in cases that need efficient publication of historical data.

Confidential Computing with “Pacts”

The Pact programming language comes from one of its key features, known as “Pacts”. “Pacts” solve a significant blockchain problem in privacy-preserving blockchains. To maintain privacy on a blockchain, participants can only run a subset of smart contracts. In these cases, the databases of each of the participants become disjointed.

Pact solves this problem using coroutines. Coroutines are functions that can start and stop at critical points in a function’s execution. These coroutines are called pacts. They define the steps to be executed by different entities as sequential transactions on the blockchain.

Learn More

The features described in this post are only a few of the crucial features that make Pact such a powerful language for writing smart contracts. There are many resources available to help you learn more about Pact. Here are a list of resources you can use to get started.

Where to go next


Receive important developer updates