in Blockchain, Blockchain stack, Ethereum, Solidity, Truffle

Truffle 3 – Using Truffle Contract (formerly EtherPudding) (Blockchain stack #4b)

This post shows you how to use Truffle Contract as part of the Truffle 3 framework.  It follows on from the previous post on Installing, deploying and running Truffle 3 on Ethereum.

Install truffle-contract using NPM.

cd ~
npm install truffle-contract

Make a copy of the Apache directory created from the previous truffle post.

$ cd /var/www/html/
$ cp -r truffleBasic truffleContract

There was no bower package for Truffle Contract at the time of writing so copy the JS files over manually from the NPM directory.

cd /var/www/html/truffleContract
mkdir javascript
mkdir javascript/truffle-contract
mkdir javascript/truffle-contract/dist
cp -R ~/node_modules/truffle-contract/dist/ ./javascript/truffle-contract/

Update the index.html in the truffleContract directory to this:

The key difference between this and the standard Ethereum contract JS API is that this can load a truffle JSON file that contains the address of your contract.  This means that you do not need to hard code the address into the HTML.  You will see that this proves useful when we start improving Ethereum DevOps using the Truffle Default Builder.

Truffle contract also manages synchronisation and promises in a way that some would say is easier and less error prone to program.

Next in the Blockchain stack series

The next post in the series, Ethereum DevOps using the Truffle Default Builder, shows you how to make your Ethereum DevOps more efficient by using the Truffle Default Builder.

Ziggify Blockchain

There’s a team of us that have come together at Ziggify to work on a Blockchain play. We are in the exploration phase, so if you want to get involved or have an idea please get in touch. I’m based in London and enjoy chewing the Blockchain fat over a cuppa or a beer.


Write a Comment



  • Truffle 3 - Ethereum DevOps using the Truffle Default Builder (Blockchain stack #4c) - Ziggify

    […] on the previous tutorials showing you how to install and run Truffle and how to use the upgraded Truffle Ethereum Contract to abstract away some of the […]