1.1 Truffle + Ganache
1.2 Truffle + Geth + EthereumWallet(或Mist)
https://ethfans.org/posts/ethereum-development-walkthrough-part-1-smart-contracts
https://ethfans.org/posts/ethereum-development-walkthrough-part-2-truffle-ganache-geth-and-mist
https://ethfans.org/posts/ethereum-development-walkthrough-part-3
1.1 windows7 + node v6.10.3 + truffle v4.1.3 + ganache-cli v6.1.0
1.2 windows7 + node v6.10.3 + geth 1.8.2 + Ethereum Wallet
Truffle: 合约框架
Ganache: 测试网络
ganache-cli -p 7545
truffle compile
truffle migrate --network development
truffle console --network development
web3.eth.account
......
Truffle: 合约框架
Geth: 搭建本地区块链测试网络
EthereumWallet: 以太坊钱包,用于观察,部署合约
EthereumWallet(或Mist)依赖于geth
在项目根目录下开启命令窗口,输入:
初始化区块数据
geth --datadir=./chaindata/ init ./genesis.json
启动区块链网络
geth --datadir=./chaindata/ --rpc --rpcapi db,eth,net,web3,personal,web3
开启另一个窗口,将以太坊钱包链接到测试网络
EthereumWallet --rpc http://127.0.0.1:8545
输入密码,例如:123456789
开启另一个命令窗口,输入:
Linux: geth attach ipc:Users/zzs/develop/eth/data-test/geth.ipc
attach后面的为在Linux环境下geth数据存储目录下的geth.ipc文件
windows: geth attach ipc:\.\pipe\geth.ipc
windows直接运行get attach报错,通过管道指定geth.ipc解决;或直接geth attach http://127.0.0.1:8545
开始挖矿:miner.start()
停止挖矿:miner.stop()
personal.unlockAccount('0x4FD9B9D689FF9c40520eeeD26d7081075980D4A5', '123456789')
personal.unlockAccount('0x1bad00FC9EE40E7C317Ce8A45049e26E3471EC5D', '123456789')
truffle migrate --network ourTestNet
truffle console --network ourTestNet
Wrestling.address
JSON.stringify(Wrestling.abi)
......
ganache-cli -p 7545
truffle test --network development
Wrestling.deployed().then(inst => { WrestlingInstance = inst })
account0 = web3.eth.accounts[0]
account1 = web3.eth.accounts[1]
WrestlingInstance.registerAsAnOpponent({from: account1})
WrestlingInstance.wrestle({from: account0, value: web3.toWei(2, "ether")})
WrestlingInstance.wrestle({from: account1, value: web3.toWei(3, "ether")})
// End of the first round
WrestlingInstance.wrestle({from: account0, value: web3.toWei(5, "ether")})
WrestlingInstance.wrestle({from: account1, value: web3.toWei(20, "ether")})
// End of the wrestling
WrestlingInstance.wrestler1.call()
WrestlingInstance.wrestler2.call()
WrestlingInstance.gameFinished.call()
WrestlingInstance.theWinner.call()
WrestlingInstance.withdraw({from: account1})
account1必须为赢家地址,若不是提币会回滚
WrestlingInstance.clearState({from: account1})
web3.eth.getBalance(web3.eth.accounts[0])
此环境下运行合约,原教程里不包含,是我自己为后续合约web化所做的尝试。
根目录下 npm init
根目录下 npm install truffle-contract
根目录下 npm install web3
var Web3 = require('web3');
var contract = require("truffle-contract");
var config = require('./build/contracts/wrestling7.json')
根目录下 node ./nodejsEnv/wrestling.js