How to install and execute Truffle on an Ubuntu 16.04

About

Truffle is a development environment, testing framework and asset pipeline for Ethereum, aiming to make life as an Ethereum developer easier.
See details on truffle website: http://truffle.readthedocs.io/en/latest/

This was made on an Ubuntu 16.04
Written with Benjamin from Ethereum Bruxelles

Installation

Install packages

First, update and install packages

# sudo apt-get update && sudo apt-get -y upgrade
# sudo apt-get -y install curl git vim build-essential

Install NodeJs

Install NodeJs to execute the DAPP

# curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
# sudo apt-get install -y nodejs
# sudo npm install -g express

Install Truffle

Install Truffle packages

# sudo npm install -g truffle

Install testrpc

testprc uses ethereumjs to simulate full client behavior and make developing Ethereum
Install testrpc

# sudo npm install -g ethereumjs-testrpc

Launch testrpc

# testrpc

Output should display

EthereumJS TestRPC v2.1.0
Available Accounts
==================
(0) 0x2742c08e81208d01ff48a8c0f7d7c738625f92f5
(1) 0x7947d5e07ab4736edbdfdd421e60ca42205a097f
...

Create a project

Init Truffle project

# mkdir myproject
# cd myprojet/
# truffle init
# truffle compile

Deploy contracts

testrpc should be launched
Deploy contracts on local chain

# truffle migrate

It should launch transaction on testrpc process output

Listening on localhost:8545
eth_accounts
eth_sendTransaction
  Transaction: 0xc1cbc63cd0644604bc41ebbd9bd9998ce14f5ae2b27cb2e2d3fc5ce823574e62
  Contract created: 0xbbdef31b721512c7c9bc05a00e8c24fa4e15e1f6
  Gas usage: 139321
  Block Number: 0x01
 
And run migration
Running migration: 1_initial_migration.js
  Deploying Migrations...
  Migrations: 0xbbdef31b721512c7c9bc05a00e8c24fa4e15e1f6

Create DAPP

To build your frontend, run:

# truffle build

Launch server for DAPP testing

# truffle serve

Output should display

Serving app on port 8080...
Rebuilding...
Completed without errors

Optional: add -p option to change port

Go to http://localhost:8080 to see the Dapp
You can send Metacoin to an address (ex: 0x2742c08e81208d01ff48a8c0f7d7c738625f92f5 as see above from testrpc)
Each transactions are displayed on the testrpc process output

Raphaël has written 45 articles

10 thoughts on “How to install and execute Truffle on an Ubuntu 16.04

  1. Aliaksandr says:

    This is one of the best tutorials.

    However I had issues on both 14.04 and 16.04…

    On 14.04 I had to do
    $ npm install -g node-sass@3.13.1
    because truffle installation failed.

    On 16.04 apt-get update failed with “AppStream cache update completed, but some metadata was ignored due to errors” so I had to enable “Pre-release updates (xenial-proposed)”.

    Fucking Linux. Nothing works out-of-the-box. And it’s Ubuntu. I can imagine what would I face using a less popular/documented distro.

    Truffle’s official documentation says you only need
    NodeJS 5.0+ installed and
    $ npm install -g truffle

    Not on my life.

  2. amit says:

    Unable to install ethereumjs-testrpc

    Getting error as

    npm ERR! Linux 4.2.0-27-generic
    npm ERR! argv “/usr/bin/nodejs” “/usr/bin/npm” “install” “-g” “ethereumjs-testrpc”
    npm ERR! node v6.10.0
    npm ERR! npm v3.10.10
    npm ERR! code ECONNRESET

    npm ERR! network tunneling socket could not be established, statusCode=407
    npm ERR! network This is most likely not a problem with npm itself
    npm ERR! network and is related to network connectivity.
    npm ERR! network In most cases you are behind a proxy or have bad network settings.
    npm ERR! network
    npm ERR! network If you are behind a proxy, please make sure that the
    npm ERR! network ‘proxy’ config is set properly. See: ‘npm help config’

    npm ERR! Please include the following file with any support request:
    npm ERR! /home/****/npm-debug.log

  3. Josh says:

    Getting an error when attempting to run ‘truffle init’:

    Error: getaddrinfo ENOTFOUND raw.githubusercontent.com raw.githubusercontent.com:443

    I am behind a proxy. I have updated npm’s config to use the proxy, but I don’t see anywhere to do the same from within truffle. (Does truffle have its own proxy config like this?)

  4. troy_007 says:

    when i will run “truffle migrate” it shows me this error.
    How can i resolve this ?? please help.

    m@m:~/myproject$ truffle migrate
    Error: Cannot find module ‘truffle-expect’
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object. (/usr/lib/node_modules/truffle/build/cli.bundled.js:85773:14)

  5. blackbutler says:

    Do I require some front end build to :
    or it is inbuilt in truffle:
    I m facing error when firing truffle build
    >Error building:

    No build configuration specified. Can’t build.

    can anyone provide a guide to that too if any.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>