https://chriseth.github.io/browser-solidity/
1.1 通过NPM / node.js命令在线安装
npm install solc
如何使用nodejs包的详细信息可以在代码库中找到:https://github.com/chriseth/browser-solidity#nodejs-usage%E3%80%82
1.2 二进制安装包
包括Mix IDE的二进制Solidity安装包在Ethereum网站C++ bundle中下载:https://github.com/ethereum/webthree-umbrella/releases%E3%80%82
1.3 从源码构建
在MacOS X、Ubuntu和其它类Unix系统中编译安装Solidity非常相似。这个指南开始讲解如何在每个平台下安装相关的依赖软件,然后构建Solidity。
1.4 MacOS X
Homebrew
Xcode
brew update
brew install boost --c++11 # 需要等待一段时间
brew install cmake cryptopp miniupnpc leveldb gmp libmicrohttpd libjson-rpc-cpp # 仅仅安装Mix IDE和Alethzero
brew install xz d-bus
brew install llvm --HEAD --with-clang
brew install qt5 --with-d-bus # 避免长时间的等待没有提示,可以添加 —verbose 输出信息。
xcode-select —install
sudo apt-add-repository ppa:george-edison55/cmake-3.x
sudo apt-get -y update
sudo apt-get -y install language-pack-en-base
sudo dpkg-reconfigure locales
sudo apt-get -y install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential git cmake libboost-all-dev libgmp-dev libleveldb-dev libminiupnpc-dev libreadline-dev libncurses5-dev libcurl4-openssl-dev libcryptopp-dev libjson-rpc-cpp-dev libmicrohttpd-dev libjsoncpp-dev libedit-dev libz-dev
sudo apt-get -y install build-essential git cmake libboost-all-dev libgmp-dev libleveldb-dev libminiupnpc-dev libreadline-dev libncurses5-dev libcurl4-openssl-dev libcryptopp-dev libjsonrpccpp-dev libmicrohttpd-dev libjsoncpp-dev libedit-dev libz-dev
git clone --recursive https://github.com/ethereum/webthree-umbrella.git
cd webthree-umbrella
./webthree-helpers/scripts/ethupdate.sh --no-push --simple-pull --project solidity # 更新Solidity库
./webthree-helpers/scripts/ethbuild.sh --no-git --project solidity --all --cores 4 -DEVMJIT=0 # 编译Solidity及其它
# 在OS X系统加上DEVMJIT将不能编译,在Linux系统上则没问题
git clone --recursive https://github.com/ethereum/webthree-umbrella.git
cd webthree-umbrella && mkdir -p build && cd build
cmake ..
contract ZhaoxiStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
contract ZhaoxiCoin {
// 关键字“public”使变量能从合约外部访问。
address public minter;
mapping (address => uint) public balances;
// 事件让轻客户端能高效的对变化做出反应。
event Sent(address from, address to, uint amount);
// 这个构造函数的代码仅仅只在合约创建的时候被运行。
function ZhaoxiCoin() {
minter = msg.sender;
}
// 合约创建者可以调用mint
function mint(address receiver, uint amount) {
if (msg.sender != minter) return;
balances[receiver] += amount;
}
// send可以被拥有代币的任何人调用
function send(address receiver, uint amount) {
if (balances[msg.sender] < amount) return;
balances[msg.sender] -= amount;
balances[receiver] += amount;
Sent(msg.sender, receiver, amount);
}
}
function minter() returns (address) { return minter; }
function balances(address _account) returns (uint balance) {
return balances[_account];
}
ZhaoxiCoin.Sent().watch({}, '', function(error, result) {
if (!error) {
console.log("ZhaoxiCoin transfer: " + result.args.amount +
" coins were sent from " + result.args.from +
" to " + result.args.to + ".");
console.log("Balances now:\n" +
"Sender: " + ZhaoxiCoin.balances.call(result.args.from) +
"Receiver: " + ZhaoxiCoin.balances.call(result.args.to));
}
}
下期预告
长按二维码关注公众号
明天将发布区块链技术(三):
智能合约入门