How Our Contract Will Work

1. Person One creates a new arbitration instance and gives it a description. 🌟

2. Person One and Person Two submit their differing opinions. 😠

3. Person One and Person Two also choose an arbiter. The process doesn’t go forward until both agree on the same account address. 👍

4. The arbiter reviews the two points of view and decide the winner. 🤔 ➡ 🏆

Setup

F eel free to move to the next section if you’ve run a truffle project before

We’ll be using a framework called Truffle to develop our smart contract. It’s a one stop shop for handling compilation, testing, deployment, migrations and much more. We’ll only be using certain features in this post but I encourage you to dig deeper.

Before we dive in, globally install truffle and testrpc.

npm install -g truffle ethereumjs-testrpc

Then, in a new directory run:

truffle init

You should see truffle’s folder structure inflate with some simple examples in the contracts/ folder.

Get Your Feet Wet

Let’s get a feel for the workflow.

1. Kickstart our test client with testrpc . You’ll see some of the accounts you’ll be using to simulate the interaction:

2. In separate tab run truffle compile . This generates a corresponding JSON artifacts from the contracts and drops them into a build folder.

3. Now run truffle migrate to generate files to facilitate contract deployment to the blockchain. Important, testrpc must be running when you migrate, otherwise your contracts won’t deploy to that testing instance.

4. Run truffle console which will connect to our running Ethereum client and allow us to interact with our contracts.

Poke Around

We’re going to modify one of the existing contracts (technically a library… works for our purposes though) ConvertLib.sol . It provides a single method to multiply two numbers.

A method that changes state on the chain is a transaction (costs gas) while any method that only returns data is a call (free).

Truffle’s console has web3 and our contracts ready to go, give it a go:

// get the deployed contract by its class name, returns a promise

> const contract = ConvertLib.deployed() // invoke the 'convert' method with 'call', also returns a promise

> const response = contract.then(c => c.convert.call(5, 20)) // print out our result!!

> response.then(res => res.toNumber()) 100

Great, we’ve interacted with a deployed contract to multiply two numbers!