搭建自己的私链
step1:建立目录和genesis.json
step2:使用命令行,创造创世块
geth --datadri "./" init genesis.json
geth中保存的是区块链的相关数据,keystore保存的是该条链中的用户信息
step3:创建自己的私链并打开控制台
geth --datadir "./” --nodiscover console
step4:在自己的私链上创建用户
eth.accounts //查看该条链上的账户
personal.newAccount("pssword")//创建一个新的账户,该账户的密码是passowrd
step5:输出区块链的log
geth --datadir "./" --nodiscover console 2>>geth.log
step6:开始挖矿
miner.start()
step7:查看主账户以太币的数量
acc0 = eth.accounts[0]
eth.getBalance(acc0)
step8:在两个账户之间进行以太币转换
acc0 =eth.accounts[0]
acc1=eth.accounts[1]
amount = web3.toWei(0.01)
eth.sendTransaction({from :acc0 , to :acc0, value :amount}) //进行交易
step9:解锁账户
这个是以太坊的一个保护机制,每隔一段时间账户就会自动锁定,这个时候任何以太币在账户之间的转换都会被拒绝,除非把该账户解锁.
personal.unlockAccount(acc0) //需要输入密码
在重启上面进行以太币转换
step10:部署合约
var a_demotypesContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"f","outputs":[{"name":"b","type":"uint256"}],"payable":false,"type":"function"}]);
var a_demotypes = a_demotypesContract.new(
{
from: web3.eth.accounts[0],
data: '0x6060604052341561000c57fe5b5b60ab8061001b6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063b3de648b14603a575bfe5b3415604157fe5b60556004808035906020019091905050606b565b6040518082815260200191505060405180910390f35b600060006008830290508091505b509190505600a165627a7a7230582010decdc0b0a43b565814fe904eae2544665457d6353c7d906fc2c43c81c867e40029',
gas: '1000000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
}) //这是我们的合约
a_demotypes
a_demotypes.f.call(100)
a_demotypes.f.call(125)