Hands-On Blockchain for Python Developers
上QQ阅读APP看书,第一时间看更新

Installing Truffle and Solidity

Truffle is a development framework for developing a smart contract with Solidity. You can create one without Truffle, but Truffle makes it easier. Without Truffle, you can still write a smart contract, but to compile it, you have to launch the Solidity compiler with certain flags. Then, in order to deploy this smart contract to the blockchain, you have to create a script to send the bytecode to the blockchain. With Truffle, in order to compile, you call the, truffle compile command, and to deploy a smart contract to the blockchain, you call the truffle migrate command after writing a simple migration script. Truffle also provides you with a tool for interacting with the smart contract in the blockchain network. It has everything you need to develop a smart contract. As stated previously, however, we will not be using this framework in the next chapter.

We are going to start by installing Truffle using the Node.js package manager. In Ubuntu Linux, in order to install Truffle globally, we have to use sudo. As described in the previous paragraph, Truffle is a smart contract development framework containing many tools, including a console application to interact with the blockchain network and the development blockchain software. On top of that, with Truffle, you get the Solidity compiler as well.

But first, you need to make sure npm installs software globally in your home directory:

$ mkdir ~/.npm-global
$ npm config set prefix '~/.npm-global'

Then append this line to the ~/. profile file:

export PATH=~/.npm-global/bin:$PATH

Now, open a new Terminal so that the new profile file takes effect or, alternatively, do the following:

$ source ~/.profile

Then, we can install Truffle as follows:

$ npm install -g truffle
$ truffle version
Truffle v5.0.2 (core: 5.0.2)

Solidity v0.5.0 (solc-js)
Node v10.15.0