TestRPC Purpose

To help people remember the installation process for TestRPC and Truffle on Ubuntu Linux. Also, to provide useful information for testing smart contracts.


Ethereum Smart Contract Testing - Installing Truffle and Testrpc

Hi everyone,

I quickly wrote these instructions on how to install Truffle and testrpc on Ubuntu Linux to test smart contracts before deploying them to an Ethereum Virtual Computer. I made it to help me remember for next time, but perhaps someone else will find it useful as well!

You can install these development tools directly onto your workstation, but I prefer to use an Ubuntu virtual machine running in VirtualBox. This way you can separate your development environment from your general purpose desktop environment. Also, it's safer to test software installations in a virtual machine before installing them on your main workstation.

Installation

First we will install NVM (Node Version Manager), a batch script that can install and manage multiple Node.js versions. You can use the curl command to download and run the installation script for nvm:

sudo curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash

During the installation, you may see some error messages:

Failed to download 'https://raw.githubusercontent.com/creationix/nvm/v0.31.4/nvm-exec'
bash: line 293: /nvm.sh: No such file or directory

You should be able to safely ignore these errors. Close the terminal window and re-open it. Type the command:

nvm


If you see the nvm help, then it has been installed successfully. Now you can install Node.js using NVM:

nvm install 5 (Truffle recommends at least version 5)

Next, we need to install npm (a package manager for Node.js). We will use it to install testrpc and Truffle:

sudo apt-get install npm

Now we can use npm to install testrpc, a Node.js Ethereum client that mimics a real Ethereum node:

npm install -g ethereumjs-testrpc

In order to install Truffle, we also need to install git (and the build-essential package if it's not installed by default).

sudo apt-get install git
sudo apt-get install build-essential

Now we can install Truffle using npm:

sudo npm install -g truffle

Are you getting any error messages? Check the Troubleshooting section below.

Start Testrpc and Initialize Truffle

To start testrpc, open a command terminal and type testrpc. It will run in background and wait for connections.

Next, open a new terminal window, create a project folder, go into it, and initialize Truffle:

mkdir myproject
cd myproject
tuffle init
(this command will create a file structure within the current directory)

Now you can test the default Truffle project (MetaCoin) by issuing the command:

truffle test

You should get three passing tests. If so, you've successfully installed Truffle and testrpc!

Troubleshooting

Potential error messages during Truffle installation:

npm ERR! Linux 4.4.0-34-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "truffle"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn

npm ERR! deasync@0.1.7 install: node ./build.js
npm ERR! spawn ENOENT
*npm ERR! *
npm ERR! Failed at the deasync@0.1.7 install script 'node ./build.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.

Why is npm reporting node v4.2.6 after we just installed version 5? Ubuntu may come with an older version of nodejs installed by default. Remove it and then try the installation again:

Check if you already have nodejs installed:

nodejs --version

To remove it:

sudo apt-get purge nodejs

Having any other problems installing Truffle? Check out the issues on Github

TestRPC Next Steps

@brennanhm has provided useful information about Truffle and TestRPC.

TestRPC 2024 Update

Since this article was published, TestRPC has become part of Ganache CLI. So please see that article for installing TestRPC. Otherwise, search for more recent TestRPC installation articles. Or browse related pages:
  • Ganache CLI Install - testRPC/ganache-cli testRPC/ganache-cli is a node.js Ethereum client for testing and development of the Smart… by technological.
  • Ethereum TestRPC and Tester Client - This provider automatically spins up the eth-testrpc server for you so that you can test your web3.py code against an in memory EVM. This provides lightning …
  • Ethereum TestRPC vs. Geth - Ethereum TestRPC vs. Geth explains that TestRPC is a client for testing and developing. While Geth is a full GO language client for connecting to the blockchain.
  • TestRPC & Ethereum Smart Contracts - … testrpc. For truffle test, testrpc or geth is required to be run explicitly. Else, you get the following error: $ truffle test Could not connect to your …

For more info, enter your Hive questions or topics into Findonni search box.


Leave Ethereum Smart Contract Testing - Installing Truffle and Testrpc to browse Brennan's Blog.

Learn more about the author at Brennan's website.
Ethereum Smart Contract Testing - Installing Truffle and Testrpc was published on and last updated on 13 Apr, 2024.