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