准备工作
安装git
输入以下命令安装Git:
sudo apt-get install git
安装solc
输入以下命令安装solc:
sudo npm install -g solc
root@i-colbyo7v:/home/ubuntu# npm install -g solc
/usr/local/node-v8.1.2-linux-x64/bin/solcjs -> /usr/local/node-v8.1.2-linux-x64/lib/node_modules/solc/solcjs
+ solc@0.4.13
added 65 packages in 59.744s
我们就会发现在终端中输入solc命令返回一个出错信息。这是因为solc只是一个程序集,如果我们想要在终端中使用solc程序编译智能合约,则需要安装solc-cli,这是solc的命令行界面。
输入以下命令安装solc-cli:
sudo npm install -g solc-cli
root@i-colbyo7v:/home/ubuntu# npm install -g solc-cli
/usr/local/node-v8.1.2-linux-x64/bin/solc -> /usr/local/node-v8.1.2-linux-x64/lib/node_modules/solc-cli/dist/index.js
npm WARN solc-cli@0.3.0 requires a peer of solc@^0.3.5 but none was installed.
+ solc-cli@0.3.0
added 20 packages in 18.604s
输入以下命令可以一并安装solc和solc-cli7(推荐使用此命令安装):
sudo npm install -g solc solc-cli --save-dev
如果输入solcjs --help命令,有以下输出,则表明solc和solc-cli安装成功:
zcc@ubuntu:~$ solcjs --help
Usage: solcjs [options] [input_file...]
Options:
--version Show version number [boolean]
--optimize Enable bytecode optimizer. [boolean]
--bin Binary of the contracts in hex. [boolean]
--abi ABI of the contracts. [boolean]
--interface Solidity Interface of the contracts. [boolean]
--output-dir, -o Output directory for the contracts. [string]
--help Show help [boolean]
到了这里,如果想以后的智能合约编译工作不使用geth控制台来完成,那么solc编译器就算安装完了。但是,如果我们需要在geth控制台使用solc编译器,那么我们仍然需要安装solc二进制包。输入以下命令安装solc二进制包8:
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc
安装Geth客户端
有多种以太坊客户端,安装Go-ethereum输入以下命令13:
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
ubuntu@i-5tthrr8u:~$ geth --help
NAME:
geth - the go-ethereum command line interface
Copyright 2013-2017 The go-ethereum Authors
USAGE:
geth [options] command [command options] [arguments...]
VERSION:
1.6.6-stable-10a45cb5
COMMANDS:
init Bootstrap and initialize a new genesis block
import Import a blockchain file
export Export blockchain into file
removedb Remove blockchain and state databases
dump Dump a specific block from storage
monitor Monitor and visualize node metrics
account Manage accounts
wallet Manage Ethereum presale wallets
console Start an interactive JavaScript environment
attach Start an interactive JavaScript environment (connect to node)
js Execute the specified JavaScript files
makedag Generate ethash DAG (for testing)
version Print version numbers
bug opens a window to report a bug on the geth