Skip to content
The Pact Smart Contract Language
Branch: master
Clone or download
LindaOrtega and slpopejoy Adds Proof field to ContMsg (#505)
* WIP Added proof field to ContMsg and changed data field type

* Adds proof field to ContMsg

* Makes proof field a ByteString
Latest commit 05ee18c May 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Document capabilities and module governance in reference docs (#500) May 16, 2019
examples Pacts in backend (#496) May 6, 2019
executables Close to working with slimmed down set of changes May 7, 2018
log added pact serve to command line Feb 9, 2017
pact-lang-api.js Privacy API first version done! May 3, 2017
src-ghc/Pact Adds Proof field to ContMsg (#505) May 21, 2019
src Adds Proof field to ContMsg (#505) May 21, 2019
tests Adds Proof field to ContMsg (#505) May 21, 2019
web Dep versions widened for both GHCJS and normal build; test passing Nov 5, 2017
.gitignore Nix gitignore (#352) Jan 9, 2019
.gitlab-ci.yml [WIP] Build Pact statically (#415) Mar 16, 2019
.travis.yml .travis.yml: don't test with nightlies Jan 29, 2019
.weeder.yaml Some cleanup from Weeder run and weeder config file Mar 14, 2018
CHANGELOG.md 2.6.1 ready Nov 21, 2018
HLint.hs Completed with type-directed partial flagging Jan 27, 2019
LICENSE simple command construction finished Feb 9, 2017
README.md module load from db (#482) Apr 29, 2019
Setup.hs Pact open-source release Nov 13, 2016
appveyor.yml appveyor.yml: update (#426) Mar 16, 2019
cabal.project Support ghc-8.6 (#483) Apr 29, 2019
collectArtifacts.sh Add mac binary to artifacts Dec 14, 2018
config.yaml No caching in SQLite layer, txid in beginTx, tx validation Feb 13, 2017
default.nix Update dependencies to sbv 8.1 (newly released). (#434) Mar 16, 2019
pact.cabal JSON serialization of Term/Scope (#473) Apr 24, 2019
repl.sh Pact open-source release Nov 13, 2016
shell.nix Add shell.nix to make plain nix-shell do the right thing Dec 18, 2018
stack-ghcjs.yaml Upgrade thyme for #6, document formats, 2.3.6 release prep Dec 13, 2017
stack-nix.yaml Update to latest reflex-platform with GHC 8.4 Nov 6, 2018
stack.yaml Update dependencies to sbv 8.1 (newly released). (#434) Mar 16, 2019
static.nix Sbv in static (#440) Mar 20, 2019

README.md

The Pact Programming Language

Build Status

This is the source code repository for Pact, a language for developing smart contracts to run on a fast deterministic blockchain.

References

Pact Homepage

Pact Tutorials

Pact Reference Docs

Pact Whitepaper

Quick Start: Browser

The easiest way to try Pact is in the browser.

Quick Start: Atom

To start writing smart contracts, the best way to go is to use the Atom editor and install language-pact using the package manager.

Installing Pact with Homebrew (OSX only)

You'll then need to install the Pact interpreter/REPL. On Mac, the easiest way to install pact is with Homebrew.

Make sure that Homebrew has been installed in your machine. Instructions for how to install it can be found here.

Once Homebrew is installed, run the following command to install pact:

brew install kadena-io/pact/pact

However, see note below about z3 compatibility.

Installing Pact with Binary Distributions

Pact can also be installed by following the instructions below:

  • Install z3. See note below about z3 compatibility.
  • Download the prebuilt binaries for your distribution. Or see Building for instructions on how to build Pact from the source code.
  • Once you've downloaded the binary, make sure that it is marked as executable by running chmod +x <executable-file>.
  • Put the binary somewhere in your PATH.

For installing pact on Linux distributions in the Arch family, refer to this package on the AUR.

z3 Compatibility

Pact users generally can use the production versions of Z3. However, with the current version at time of writing, 4.8.4, use of the function str-to-int can cause problems, and for those building from source or hacking Pact Haskell code, a unit test will fail/hang indefinitely because of this.

The fix is to use the older version 4.8.3:

  • For Mac homebrew users, 4.8.3 can be installed via brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/a7e7806193f7605c7fef6110655911012d3f1eb3/Formula/z3.rb.
  • Z3 binaries are available on github for manual installation (Pact uses the z3 in your $PATH).
  • Nix builds install the correct version.

Verifying Install

Test by issuing pact in a terminal. Try out some commands:

$ pact
pact> (+ 1 2)
3
pact> (+ "hello, " "world")
"hello, world"

There are examples in this source repository of working smart contracts which you can load into Atom to get started.

Quick Start: Pact REST API Server

Pact now features a full REST API HTTP server and SQLite database implementation, making blockchain application development painless and easy. The Pact server simulates a single-node blockchain environment, with the same API supported by the Kadena ScalableBFT blockchain.

To start the server, issue pact --serve CONFIG or pact -s CONFIG, where CONFIG is a valid config.yaml.

REST API Docs

The REST API is documented at http://pact-language.readthedocs.io/en/latest/pact-reference.html#rest-api.

Related Projects

Hosting static files.

The HTTP server will host any static files it finds in its working directory.

Config file format

The pact dev server (pact-serve) requires a configuration Yaml file (e.g. server.conf) to operate. The documentation for it is:

➜  pact git:(feat/dev-server) pact --serve --help
Config file is YAML format with the following properties:
port       - HTTP server port
persistDir - Directory for database files.
             If ommitted, runs in-memory only.
logDir     - Directory for HTTP logs
pragmas    - SQLite pragmas to use with persistence DBs
verbose    - [True|False] Provide extra logging information

Replay from disk.

When running pact-serve with persistence enabled, the server automatically replays from the database commands.sqlite in the persist dir. To prevent replay, simply delete this file before starting the server.

Building Pact

Building with Stack

Install stack

Issue stack build on the command line.

Use stack install to install on the command line and for Atom, ensuring that $HOME/.local/bin is on your PATH.

Building with Nix / NixOS

  1. Go to https://nixos.org/nix/, click "Get Nix", follow the instructions to install the Nix package manager.
  2. Edit $NIX_CONF_DIR/nix.conf.
    • Linux default: /etc/nix/nix.conf
  3. Set the substituters and trusted-public-keys lines as follows:
substituters = https://pact.cachix.org https://nixcache.reflex-frp.org https://cache.nixos.org/

trusted-public-keys = pact.cachix.org-1:cg1bsryGrHnQzqEp52NcHq4mBBL+R25XbR2Q/I/vQ8Y= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

NOTE: In older versions of Nix, instead of substituters and trusted-public-keys, use binary-caches and binary-cache-public-keys respectively.

  1. If running Nix in multi-user mode (i.e. with a daemon), restart the Nix daemon.

On Mac:

sudo launchctl stop org.nixos.nix-daemon
sudo launchctl start org.nixos.nix-daemon

On Linux:

sudo systemctl restart nix-daemon.service
  1. Run nix-build from the project root.

Incremental Builds

Building with nix-build does a full rebuild every time, which is usually not what you want when developing. To do incremental builds, you need to enter a nix shell. To do that use the nix-shell command.

This puts you in a shell that has all the necessary dependencies installed. Once inside this shell you can build as normal with cabal using cabal build or cabal new-build.

You can also build with stack inside this shell as follows:

$ stack --stack-yaml stack-nix.yaml build

Hoogle Documentation

Nix has out-of-the-box Hoogle integration. It allows you to run a local Hoogle server with docs for all of the project dependencies. This is really nice for two reasons:

  1. You know you're getting correct docs for the exact versions of the packages you are depending on.

  2. You don't have to have an internet connection to access them.

To start the hoogle server, run this command from the project root directory.

nix-shell --run 'hoogle server --local'

This runs hoogle locally on port 8080. Running it this way, however, does not include haddocks for the pact (or whatever tho local project is). It only includes docs for the dependencies. To fix this, use the following command instead:

nix-shell -p 'with import ./. {}; ghc.ghcWithHoogle (p: [p.pact])' --run 'hoogle server --local'

To use the above command for other projects that use the .project function replace [p.pact] with a list of all the locally defined projects to include. For example: [p.backend p.common p.frontend] for a project that has those three separate local packages.

License

This code is distributed under the terms of the BSD3 license. See LICENSE for details.

You can’t perform that action at this time.