On this page:
Reach:   The Safest and Easiest DApp Programming Language
0.1.3

Reach: The Safest and Easiest DApp Programming Language

Jay McCarthy <jay@reach.sh>

Reach is a domain-specific language for building decentralized applications (DApps).

This set of documents contains everything you need to know about Reach.

If you are looking for something specific, here are some places to look:

The source of this site is available on GitHub; we welcome Pull Requests for improvements and Issues for problem reports!

    1 Overview

      1.1 Decentralized applications

      1.2 A minimal Reach program

      1.3 Compile

      1.4 Verify

      1.5 Interface

      1.6 Execute

      1.7 Web app

      1.8 Next steps

    2 Tutorial

      2.1 Install and Initialize

      2.2 Scaffolding and Setup

      2.3 Rock, Paper, and Scissors

      2.4 Bets and Wagers

      2.5 Trust and Commitments

      2.6 Timeouts and Participation

      2.7 Play and Play Again

      2.8 Interaction and Independence

      2.9 Web Interaction

      2.10 Onward and Further

      2.11 Rock, Paper, Scissors in Python

    3 Guide

      3.1 Using Reach on Windows

      3.2 How does Reach use version numbers?

      3.3 How does Reach development compare to Solidity development?

        3.3.1 Solidity Development

        3.3.2 Reach Development

        3.3.3 Conclusion

      3.4 Do I have to use JavaScript to write my frontend? What about Python, Go, or other languages?

      3.5 How do I add tracing logs to my Reach program?

      3.6 What do the different kinds of consensus transfers mean? publish, pay, race, fork, parallelReduce?

        3.6.1 Is a single participant responsible for the transfer?

        3.6.2 Are multiple participants able to cause the transfer, but each will provide different data?

        3.6.3 Are there multiple participants that each want to do different things?

        3.6.4 Will these different things happen over and over until some condition is met?

        3.6.5 Summary

      3.7 How and what to verify

      3.8 Finding and using loop invariants

      3.9 Choosing a deployment mode

      3.10 Non-participation: What it is and how to protect against it

      3.11 Determinism, simultaneity, and choice in decentralized applications

      3.12 Racing non-determinism in decentralized applications

      3.13 Building decentralized abstractions

      3.14 Testing Reach programs in the browser

        3.14.1 Algorand

          3.14.1.1 Algorand: mnemonic

          3.14.1.2 Algorand: AlgoSigner

      3.15 IDE/Text Editor Support

      3.16 Sharing and discovering shared Reach packages

      3.17 How does Reach work?

      3.18 What are Reach’s limitations?

      3.19 Reach’s Roadmap

      3.20 Reach’s Changelog

        0.1.3: 2020/07 - present

        0.1.2: 2020/09 - 2021/07

        0.1.1: 2019/09 - 2020/09

        0.1.0: 2019/09 - 2020/09

    4 Workshop

      4.1 Workshop: Hash Lock

        4.1.1 Problem Analysis

        4.1.2 Data Definition

        4.1.3 Communication Construction

        4.1.4 Assertion Insertion

        4.1.5 Interaction Introduction

        4.1.6 Deployment Decisions

        4.1.7 Discussion

      4.2 Workshop: Relay Account

        4.2.1 Problem Analysis

        4.2.2 Data Definition

        4.2.3 Communication Construction

        4.2.4 Assertion Insertion

        4.2.5 Interaction Introduction

        4.2.6 Deployment Decisions

        4.2.7 Discussion and Next Steps

      4.3 Workshop: Trust Fund

        4.3.1 Problem Analysis

        4.3.2 Data Definition

        4.3.3 Communication Construction

        4.3.4 Assertion Insertion

        4.3.5 Interaction Introduction

        4.3.6 Deployment Decisions

        4.3.7 Discussion and Next Steps

      4.4 Workshop: Fear of Missing Out

        4.4.1 Problem Analysis

        4.4.2 Data Definition

        4.4.3 Communication Construction

        4.4.4 Assertion Insertion

        4.4.5 Interaction Introduction

        4.4.6 Deployment Decisions

        4.4.7 Discussion and Next Steps

      4.5 Workshop: Fear of Missing Out Generalized

        4.5.1 Problem Analysis

        4.5.2 Data Definition

        4.5.3 Communication Construction

        4.5.4 Assertion Insertion

        4.5.5 Interaction Introduction

        4.5.6 Deployment Decisions

        4.5.7 Discussion and Next Steps

      4.6 Workshop: Fair Rock-Paper-Scissors

      4.7 Workshop: Efficient Rock-Paper-Scissors

      4.8 Workshop: Rental Agreement

      4.9 Workshop: Simultaneous Games

      4.10 Workshop: Guardian Account

      4.11 Workshop: Periodic Payment

      4.12 Workshop: Nim

      4.13 Workshop: Tic-Tac-Toe

      4.14 Workshop: Secured Loan

      4.15 Workshop: Atomic Swap

      4.16 Workshop: Atomic Swap Auction

      4.17 Workshop: Race

      4.18 Workshop: Chicken

      4.19 Workshop: Popularity Contest

      4.20 Workshop: Simple NFT

      4.21 Workshop: NFT with Auction

      4.22 Workshop: NFT with Royalties and Harberger Tax

      4.23 Workshop: Raffle

      4.24 Workshop: Rent Seeking

      4.25 Workshop: Remote Objects

      4.26 Workshop: Oracle

      4.27 Workshop: Timed English Auction

      4.28 Workshop: Crowd-funding

    5 Reference

      5.1 Installation

      5.2 Usage

        5.2.1 reach compile

        5.2.2 reach init

        5.2.3 reach run

        5.2.4 reach down

        5.2.5 reach scaffold

        5.2.6 reach react

        5.2.7 reach devnet

        5.2.8 reach rpc-server

        5.2.9 reach rpc-run

        5.2.10 reach docker-reset

        5.2.11 reach upgrade

        5.2.12 reach update

        5.2.13 reach version

        5.2.14 reach hashes

      5.3 Language Model

        5.3.1 Evaluation Model

        5.3.2 Compilation Model

        5.3.3 Syntax Model

      5.4 Programs

        5.4.1 Validity and other concepts

          5.4.1.1 Security levels and scope

          5.4.1.2 Domination

        5.4.2 Modules

          5.4.2.1 Statements

            5.4.2.1.1 export

            5.4.2.1.2 import

              5.4.2.1.2.1 Local imports

              5.4.2.1.2.2 Package imports

          5.4.2.2 Expressions

            5.4.2.2.1 Reach.App

              5.4.2.2.1.1 Deprecated long-form

        5.4.3 Application Initialization

          5.4.3.1 Statements

            5.4.3.1.1 deploy

            5.4.3.1.2 setOptions

          5.4.3.2 Expressions

            5.4.3.2.1 Participant Definition

            5.4.3.2.2 View Definition

        5.4.4 Steps

          5.4.4.1 Statements

            5.4.4.1.1 only and each

            5.4.4.1.2 Pay Amounts

            5.4.4.1.3 publish, pay, when, and timeout

            5.4.4.1.4 fork

              5.4.4.1.4.1 fork intuition

            5.4.4.1.5 wait

            5.4.4.1.6 exit

          5.4.4.2 Expressions

            5.4.4.2.1 race

            5.4.4.2.2 unknowable

            5.4.4.2.3 closeTo

        5.4.5 Local Steps

          5.4.5.1 Statements

          5.4.5.2 Expressions

            5.4.5.2.1 this

            5.4.5.2.2 interact

            5.4.5.2.3 assume

            5.4.5.2.4 fail

            5.4.5.2.5 declassify

            5.4.5.2.6 makeCommitment

        5.4.6 Consensus Steps

          5.4.6.1 Statements

            5.4.6.1.1 commit

            5.4.6.1.2 only and each

            5.4.6.1.3 View Objects

            5.4.6.1.4 Participant.set and .set

            5.4.6.1.5 while

            5.4.6.1.6 continue

            5.4.6.1.7 parallelReduce

              5.4.6.1.7.1 .timeRemaining

              5.4.6.1.7.2 .throwTimeout

              5.4.6.1.7.3 parallelReduce intuition

          5.4.6.2 Expressions

            5.4.6.2.1 this

            5.4.6.2.2 transfer

            5.4.6.2.3 require

            5.4.6.2.4 checkCommitment

            5.4.6.2.5 Token minting

            5.4.6.2.6 Remote objects

            5.4.6.2.7 Mappings: creation and modification

            5.4.6.2.8 Sets: creation and modification

        5.4.7 Computations

          5.4.7.1 Comments

          5.4.7.2 Blocks

          5.4.7.3 Statements

            5.4.7.3.1 const and function

            5.4.7.3.2 return

            5.4.7.3.3 if

            5.4.7.3.4 switch

            5.4.7.3.5 Block statements

            5.4.7.3.6 Try/Catch & Throw Statements

            5.4.7.3.7 Expression statements

          5.4.7.4 Expressions

            5.4.7.4.1 ’use strict’

            5.4.7.4.2 Identifier reference

            5.4.7.4.3 Function application

            5.4.7.4.4 Types

            5.4.7.4.5 Literal values

            5.4.7.4.6 Operator expression

            5.4.7.4.7 xor

            5.4.7.4.8 Padding

            5.4.7.4.9 Parenthesized expression

            5.4.7.4.10 Tuples

            5.4.7.4.11 array

            5.4.7.4.12 Element reference

            5.4.7.4.13 Array & tuple length: Tuple.length, Array.length, and .length

            5.4.7.4.14 Array & tuple update: Tuple.set, Array.set, and .set

            5.4.7.4.15 Array element type: Array.elemType and .elemType

            5.4.7.4.16 Foldable operations

              5.4.7.4.16.1 Foldable.forEach && .forEach

              5.4.7.4.16.2 Foldable.all && .all

              5.4.7.4.16.3 Foldable.any && .any

              5.4.7.4.16.4 Foldable.or && .or

              5.4.7.4.16.5 Foldable.and && .and

              5.4.7.4.16.6 Foldable.includes && .includes

              5.4.7.4.16.7 Foldable.count && .count

              5.4.7.4.16.8 Foldable.size && .size

              5.4.7.4.16.9 Foldable.min && .min

              5.4.7.4.16.10 Foldable.max && .max

              5.4.7.4.16.11 Foldable.sum && .sum

              5.4.7.4.16.12 Foldable.product && .product

              5.4.7.4.16.13 Foldable.average && .average

            5.4.7.4.17 Array group operations

              5.4.7.4.17.1 Array.iota

              5.4.7.4.17.2 Array.replicate && .replicate

              5.4.7.4.17.3 Array.concat && .concat

              5.4.7.4.17.4 Array.empty

              5.4.7.4.17.5 Array.zip && .zip

              5.4.7.4.17.6 Array.map && .map

              5.4.7.4.17.7 Array.mapWithIndex && .mapWithIndex

              5.4.7.4.17.8 Array.reduce && .reduce

              5.4.7.4.17.9 Array.reduceWithIndex && .reduceWithIndex

              5.4.7.4.17.10 Array.indexOf && .indexOf

              5.4.7.4.17.11 Array.findIndex && .findIndex

              5.4.7.4.17.12 Array.find && .find

              5.4.7.4.17.13 Array.withIndex && .withIndex

              5.4.7.4.17.14 Array.slice && .slice

            5.4.7.4.18 Mapping group operations

              5.4.7.4.18.1 Map.reduce && .reduce

            5.4.7.4.19 Objects

            5.4.7.4.20 Structs

            5.4.7.4.21 Field reference

            5.4.7.4.22 Object.set

            5.4.7.4.23 Object.setIfUnset

            5.4.7.4.24 Object.has

            5.4.7.4.25 Data

            5.4.7.4.26 Maybe

            5.4.7.4.27 Either

            5.4.7.4.28 match

            5.4.7.4.29 Conditional expression

            5.4.7.4.30 Arrow expression

            5.4.7.4.31 makeEnum

            5.4.7.4.32 assert

            5.4.7.4.33 forall

            5.4.7.4.34 possible

            5.4.7.4.35 digest

            5.4.7.4.36 balance

            5.4.7.4.37 lastConsensusTime

            5.4.7.4.38 makeDeadline

            5.4.7.4.39 implies

            5.4.7.4.40 ensure

            5.4.7.4.41 hasRandom

            5.4.7.4.42 hasConsoleLogger

            5.4.7.4.43 compose

            5.4.7.4.44 sqrt

            5.4.7.4.45 pow

            5.4.7.4.46 Signed Integers

            5.4.7.4.47 Fixed-Point Numbers

            5.4.7.4.48 Anybody

            5.4.7.4.49 Intervals

              5.4.7.4.49.1 Constructors

              5.4.7.4.49.2 Accessors

              5.4.7.4.49.3 Relational Operations

              5.4.7.4.49.4 Arithmetic Operations

              5.4.7.4.49.5 Other Operations

      5.5 Consensus Network Connectors

        5.5.1 Ethereum

        5.5.2 Algorand

      5.6 Participant Backends

        5.6.1 JavaScript

          5.6.1.1 Guarantees

        5.6.2 Reach RPC Server

          5.6.2.1 Reach RPC Client Standard Options

          5.6.2.2 Reach RPC Protocol Specification

          5.6.2.3 Reach RPC Protocol Client Implementation Walkthrough

      5.7 Frontend Support

        5.7.1 JavaScript

          5.7.1.1 Types

          5.7.1.2 loader.mjs

          5.7.1.3 Accounts

            5.7.1.3.1 Ethereum-specific

          5.7.1.4 Contracts

            5.7.1.4.1 View Access

          5.7.1.5 Network Utilities

          5.7.1.6 Provider Selection

          5.7.1.7 Utilities

          5.7.1.8 ask.mjs

        5.7.2 JavaScript (RPC)

        5.7.3 Python (RPC)

        5.7.4 Go (RPC)

      5.8 Error Codes

        5.8.1 RC0000

        5.8.2 RE0000

        5.8.3 RE0001

        5.8.4 RE0002

        5.8.5 RE0003

        5.8.6 RE0004

        5.8.7 RE0005

        5.8.8 RE0006

        5.8.9 RE0007

        5.8.10 RE0008

        5.8.11 RE0009

        5.8.12 RE0010

        5.8.13 RE0011

        5.8.14 RE0012

        5.8.15 RE0013

        5.8.16 RE0014

        5.8.17 RE0015

        5.8.18 RE0016

        5.8.19 RE0017

        5.8.20 RE0018

        5.8.21 RE0019

        5.8.22 RE0020

        5.8.23 RE0021

        5.8.24 RE0022

        5.8.25 RE0023

        5.8.26 RE0024

        5.8.27 RE0025

        5.8.28 RE0026

        5.8.29 RE0027

        5.8.30 RE0028

        5.8.31 RE0029

        5.8.32 RE0030

        5.8.33 RE0031

        5.8.34 RE0032

        5.8.35 RE0033

        5.8.36 RE0034

        5.8.37 RE0035

        5.8.38 RE0036

        5.8.39 RE0037

        5.8.40 RE0038

        5.8.41 RE0039

        5.8.42 RE0040

        5.8.43 RE0041

        5.8.44 RE0042

        5.8.45 RE0043

        5.8.46 RE0044

        5.8.47 RE0045

        5.8.48 RE0046

        5.8.49 RE0047

        5.8.50 RE0048

        5.8.51 RE0049

        5.8.52 RE0050

        5.8.53 RE0051

        5.8.54 RE0052

        5.8.55 RE0053

        5.8.56 RE0054

        5.8.57 RE0055

        5.8.58 RE0056

        5.8.59 RE0057

        5.8.60 RE0058

        5.8.61 RE0059

        5.8.62 RE0060

        5.8.63 RE0061

        5.8.64 RE0062

        5.8.65 RE0063

        5.8.66 RE0064

        5.8.67 RE0065

        5.8.68 RE0066

        5.8.69 RE0067

        5.8.70 RE0068

        5.8.71 RE0069

        5.8.72 RE0070

        5.8.73 RE0071

        5.8.74 RE0072

        5.8.75 RE0073

        5.8.76 RE0074

        5.8.77 RE0075

        5.8.78 RE0076

        5.8.79 RE0077

        5.8.80 RE0078

        5.8.81 RE0079

        5.8.82 RE0080

        5.8.83 RE0081

        5.8.84 RE0082

        5.8.85 RE0083

        5.8.86 RE0084

        5.8.87 RE0085

        5.8.88 RE0086

        5.8.89 RE0087

        5.8.90 RE0088

        5.8.91 RE0089

        5.8.92 RE0090

        5.8.93 RE0091

        5.8.94 RE0092

        5.8.95 RE0093

        5.8.96 RE0094

        5.8.97 RE0095

        5.8.98 RE0096

        5.8.99 RE0097

        5.8.100 RE0098

        5.8.101 RE0099

        5.8.102 RE0100

        5.8.103 RE0101

        5.8.104 RE0102

        5.8.105 RE0103

        5.8.106 RE0104

        5.8.107 RE0105

        5.8.108 RE0106

        5.8.109 RE0107

        5.8.110 RE0108

        5.8.111 RE0109

        5.8.112 RE0110

        5.8.113 RE0111

        5.8.114 RE0112

        5.8.115 RE0113

        5.8.116 RE0114

        5.8.117 REP0000

        5.8.118 RI0000

        5.8.119 RI0001

        5.8.120 RI0002

        5.8.121 RI0003

        5.8.122 RI0004

        5.8.123 RL0000

        5.8.124 RP0000

        5.8.125 RP0001

        5.8.126 RP0002

        5.8.127 RP0003

        5.8.128 RP0004

        5.8.129 RP0005

        5.8.130 RP0006

        5.8.131 RP0007

        5.8.132 RP0008

        5.8.133 RP0009

        5.8.134 RP0010

        5.8.135 RP0011

        5.8.136 RX0000

    Index