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

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.9.1 Application component

        2.9.2 Connect Account dialog

        2.9.3 Fund Account dialog

        2.9.4 Choose Role

        2.9.5 Player component

        2.9.6 Get Hand dialog

        2.9.7 Waiting for results display

        2.9.8 Done display

        2.9.9 Timeout display

        2.9.10 Deployer component

        2.9.11 Set Wager dialog

        2.9.12 Deploy dialog

        2.9.13 Deploying display

        2.9.14 Waiting for Attacher display

        2.9.15 Attacher component

        2.9.16 Attach dialog

        2.9.17 Attaching display

        2.9.18 Accept Terms dialog

        2.9.19 Waiting for Turn display

        2.9.20 Putting it all together

      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 How do network and non-network tokens differ?

        3.6.1 How do network tokens behave?

        3.6.2 How do non-network tokens violate this?

        3.6.3 Why does this matter?

        3.6.4 What does Reach do about this?

        3.6.5 What can I do about it?

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

        3.7.1 Is a single participant responsible for the transfer?

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

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

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

        3.7.5 Summary

      3.8 How and what to verify

      3.9 Finding and using loop invariants

      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 How to use Ganache with Reach

      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.7: 2021/11 - present

        0.1.6: 2021/10 - 2021/11

        0.1.5: 2021/09 - 2021/10

        0.1.4: 2021/09 - 2021/09

        0.1.3: 2021/07 - 2021/08

        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.2.15 reach config

      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 API Definition

            5.4.3.2.3 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.4.2.4 call

        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.5.2.7 didPublish

        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 unstrict

            5.4.7.4.3 Identifier reference

            5.4.7.4.4 Function application

            5.4.7.4.5 Types

            5.4.7.4.6 Literal values

            5.4.7.4.7 Operator expression

            5.4.7.4.8 xor

            5.4.7.4.9 Padding

            5.4.7.4.10 Parenthesized expression

            5.4.7.4.11 Tuples

            5.4.7.4.12 array

            5.4.7.4.13 Element reference

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

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

            5.4.7.4.16 Array element type: Array.elemType and .elemType

            5.4.7.4.17 Foldable operations

              5.4.7.4.17.1 Foldable.forEach && .forEach

              5.4.7.4.17.2 Foldable.all && .all

              5.4.7.4.17.3 Foldable.any && .any

              5.4.7.4.17.4 Foldable.or && .or

              5.4.7.4.17.5 Foldable.and && .and

              5.4.7.4.17.6 Foldable.includes && .includes

              5.4.7.4.17.7 Foldable.count && .count

              5.4.7.4.17.8 Foldable.size && .size

              5.4.7.4.17.9 Foldable.min && .min

              5.4.7.4.17.10 Foldable.max && .max

              5.4.7.4.17.11 Foldable.sum && .sum

              5.4.7.4.17.12 Foldable.product && .product

              5.4.7.4.17.13 Foldable.average && .average

            5.4.7.4.18 Array group operations

              5.4.7.4.18.1 Array.iota

              5.4.7.4.18.2 Array.replicate && .replicate

              5.4.7.4.18.3 Array.concat && .concat

              5.4.7.4.18.4 Array.empty

              5.4.7.4.18.5 Array.zip && .zip

              5.4.7.4.18.6 Array.map && .map

              5.4.7.4.18.7 Array.mapWithIndex && .mapWithIndex

              5.4.7.4.18.8 Array.reduce && .reduce

              5.4.7.4.18.9 Array.reduceWithIndex && .reduceWithIndex

              5.4.7.4.18.10 Array.indexOf && .indexOf

              5.4.7.4.18.11 Array.findIndex && .findIndex

              5.4.7.4.18.12 Array.find && .find

              5.4.7.4.18.13 Array.withIndex && .withIndex

              5.4.7.4.18.14 Array.slice && .slice

            5.4.7.4.19 Mapping group operations

              5.4.7.4.19.1 Map.reduce && .reduce

            5.4.7.4.20 Objects

            5.4.7.4.21 Structs

            5.4.7.4.22 Field reference

            5.4.7.4.23 Object.set

            5.4.7.4.24 Object.setIfUnset

            5.4.7.4.25 Object.has

            5.4.7.4.26 Data

            5.4.7.4.27 Maybe

            5.4.7.4.28 Either

            5.4.7.4.29 match

            5.4.7.4.30 Conditional expression

            5.4.7.4.31 Arrow expression

            5.4.7.4.32 makeEnum

            5.4.7.4.33 assert

            5.4.7.4.34 forall

            5.4.7.4.35 possible

            5.4.7.4.36 digest

            5.4.7.4.37 balance

            5.4.7.4.38 getContract

            5.4.7.4.39 getAddress

            5.4.7.4.40 lastConsensusTime and lastConsensusSecs

            5.4.7.4.41 baseWaitTime and baseWaitSecs

            5.4.7.4.42 Time arguments - relativeTime, absoluteTime, relativeSecs, absoluteSecs

            5.4.7.4.43 makeDeadline

            5.4.7.4.44 implies

            5.4.7.4.45 ensure

            5.4.7.4.46 hasRandom

            5.4.7.4.47 hasConsoleLogger

            5.4.7.4.48 compose

            5.4.7.4.49 muldiv

            5.4.7.4.50 sqrt

            5.4.7.4.51 pow

            5.4.7.4.52 Signed Integers

            5.4.7.4.53 Fixed-Point Numbers

            5.4.7.4.54 Anybody

            5.4.7.4.55 Intervals

              5.4.7.4.55.1 Constructors

              5.4.7.4.55.2 Accessors

              5.4.7.4.55.3 Relational Operations

              5.4.7.4.55.4 Arithmetic Operations

              5.4.7.4.55.5 Other Operations

      5.5 Consensus Network Connectors

        5.5.1 Algorand

        5.5.2 Conflux

          5.5.2.1 FAQ

            5.5.2.1.1 How do I run my Reach DApp on CFX TestNet or MainNet?

            5.5.2.1.2 How can I use ConfluxPortal with the Reach devnet?

            5.5.2.1.3 How can I use gas and storage sponsorship?

        5.5.3 Ethereum

      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 Account Handles

            5.7.1.3.1 EVM-specific (Ethereum and Conflux)

            5.7.1.3.2 Conflux-specific

          5.7.1.4 Contract Handles

            5.7.1.4.1 ctc.participants, ctc.p

            5.7.1.4.2 ctc.apis, ctc.a

            5.7.1.4.3 ctc.safeApis

            5.7.1.4.4 ctc.views, ctc.v

            5.7.1.4.5 ctc.unsafeViews

          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 C# (RPC)

        5.7.3 JavaScript (RPC)

        5.7.4 Go (RPC)

        5.7.5 Python (RPC)

      5.8 Error Codes

        5.8.1 RA0000

        5.8.2 RA0001

        5.8.3 RC0000

        5.8.4 RE0000

        5.8.5 RE0001

        5.8.6 RE0002

        5.8.7 RE0003

        5.8.8 RE0004

        5.8.9 RE0005

        5.8.10 RE0006

        5.8.11 RE0007

        5.8.12 RE0008

        5.8.13 RE0009

        5.8.14 RE0010

        5.8.15 RE0011

        5.8.16 RE0012

        5.8.17 RE0013

        5.8.18 RE0014

        5.8.19 RE0015

        5.8.20 RE0016

        5.8.21 RE0017

        5.8.22 RE0018

        5.8.23 RE0019

        5.8.24 RE0020

        5.8.25 RE0021

        5.8.26 RE0022

        5.8.27 RE0023

        5.8.28 RE0024

        5.8.29 RE0025

        5.8.30 RE0026

        5.8.31 RE0027

        5.8.32 RE0028

        5.8.33 RE0029

        5.8.34 RE0030

        5.8.35 RE0031

        5.8.36 RE0032

        5.8.37 RE0033

        5.8.38 RE0034

        5.8.39 RE0035

        5.8.40 RE0036

        5.8.41 RE0037

        5.8.42 RE0038

        5.8.43 RE0039

        5.8.44 RE0040

        5.8.45 RE0041

        5.8.46 RE0042

        5.8.47 RE0043

        5.8.48 RE0044

        5.8.49 RE0045

        5.8.50 RE0046

        5.8.51 RE0047

        5.8.52 RE0048

        5.8.53 RE0049

        5.8.54 RE0050

        5.8.55 RE0051

        5.8.56 RE0052

        5.8.57 RE0053

        5.8.58 RE0054

        5.8.59 RE0055

        5.8.60 RE0056

        5.8.61 RE0057

        5.8.62 RE0058

        5.8.63 RE0059

        5.8.64 RE0060

        5.8.65 RE0061

        5.8.66 RE0062

        5.8.67 RE0063

        5.8.68 RE0064

        5.8.69 RE0065

        5.8.70 RE0066

        5.8.71 RE0067

        5.8.72 RE0068

        5.8.73 RE0069

        5.8.74 RE0070

        5.8.75 RE0071

        5.8.76 RE0072

        5.8.77 RE0073

        5.8.78 RE0074

        5.8.79 RE0075

        5.8.80 RE0076

        5.8.81 RE0077

        5.8.82 RE0078

        5.8.83 RE0079

        5.8.84 RE0080

        5.8.85 RE0081

        5.8.86 RE0082

        5.8.87 RE0083

        5.8.88 RE0084

        5.8.89 RE0085

        5.8.90 RE0086

        5.8.91 RE0087

        5.8.92 RE0088

        5.8.93 RE0089

        5.8.94 RE0090

        5.8.95 RE0091

        5.8.96 RE0092

        5.8.97 RE0093

        5.8.98 RE0094

        5.8.99 RE0095

        5.8.100 RE0096

        5.8.101 RE0097

        5.8.102 RE0098

        5.8.103 RE0099

        5.8.104 RE0100

        5.8.105 RE0101

        5.8.106 RE0102

        5.8.107 RE0103

        5.8.108 RE0104

        5.8.109 RE0105

        5.8.110 RE0106

        5.8.111 RE0107

        5.8.112 RE0108

        5.8.113 RE0109

        5.8.114 RE0110

        5.8.115 RE0111

        5.8.116 RE0112

        5.8.117 RE0113

        5.8.118 RE0114

        5.8.119 RE0115

        5.8.120 RE0116

        5.8.121 RE0117

        5.8.122 RE0118

        5.8.123 RE0119

        5.8.124 RE0120

        5.8.125 RE0121

        5.8.126 RE0122

        5.8.127 RE0123

        5.8.128 RE0124

        5.8.129 RE0125

        5.8.130 REP0000

        5.8.131 REP0001

        5.8.132 RI0000

        5.8.133 RI0001

        5.8.134 RI0002

        5.8.135 RI0003

        5.8.136 RI0004

        5.8.137 RL0000

        5.8.138 RP0000

        5.8.139 RP0001

        5.8.140 RP0002

        5.8.141 RP0003

        5.8.142 RP0004

        5.8.143 RP0005

        5.8.144 RP0006

        5.8.145 RP0007

        5.8.146 RP0008

        5.8.147 RP0009

        5.8.148 RP0010

        5.8.149 RP0011

        5.8.150 RX0000

        5.8.151 RAPI0000

        5.8.152 RAPI0001

        5.8.153 RAPI0002

        5.8.154 RAPI0003

        5.8.155 RW0000

        5.8.156 RW0001

        5.8.157 RW0002

        5.8.158 RW0003

        5.8.159 RW0004

        5.8.160 RW0005

    Index