区块链试验

https://github.com/ethereum/go-ethereum下载客户端源码
构建geth等命令行
go install -v ./cmd/...

初始化私链,json文件放后面
geth init ./genesis.json --datadir "./chain"

geth --datadir "./chain" --nodiscover console 2>>eth_output.log
web3.personal.newAccount("123456")

把以下脚本放入here.js ,使用loadScript('./here.js')加载、
acc0 = web3.eth.accounts[0]
acc1 = web3.eth.accounts[1]
function checkbal() {
     var totalBal = 0;
     for (var acctNum in eth.accounts) {
         var acct = eth.accounts[acctNum];
         var acctBal = web3.fromWei(eth.getBalance(acct), "ether");
         totalBal += parseFloat(acctBal);
         console.log("  eth.accounts[" + acctNum + "]: 	" + acct + " 	balance: " + acctBal + " ether");
     }
     console.log("  Total balance: " + totalBal + " ether");
 };
 
function maketx() {
	web3.eth.sendTransaction({from:acc0,to:acc1,value:web3.toWei(3,"ether")})
	miner.start()
    miner.stop()        
	checkbal()
};	
 
 
web3.personal.unlockAccount(acc0,"123456")
var mshkdemoContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"mshkadd","outputs":[{"name":"","type":"address"},{"name":"b","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]);
var mshkdemo = mshkdemoContract.new(
   {
     from: web3.eth.accounts[0], 
     data: '0x608060405234801561001057600080fd5b5060f98061001f6000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063ee64a560146044575b600080fd5b348015604f57600080fd5b50606c6004803603810190808035906020019092919050505060b5565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b60008060006107d984019050338192509250509150915600a165627a7a7230582029e5190fe281a5291ff000ec7a083311b2d1b2d4de3bd2c3472c4e52faf3bf580029', 
     gas: '3000000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })

  

mshkdemoContract智能合约的代码可以通过https://remix.ethereum.org/ 生成。

智能合约对应的solidity代码如下
pragma solidity ^0.4.9;

contract mshkDemo {

     function mshkadd(uint a) public returns (address, uint b) {  
        uint resutl = a+2009;
        return (msg.sender, resutl);
    }  

}

  

 

执行智能合约

miner.start()

mshkdemo.mshkadd.call(10)

miner.stop() 

genesis.json内容

{
  "config": {
        "chainId": 10,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00",
  "alloc"      : {}
}

  

https://www.cnblogs.com/lion.net/p/7809862.html

http://www.cnblogs.com/lion.net/p/7809891.html

http://www.hyipc.com/?p=974

原文地址:https://www.cnblogs.com/coolyylu/p/8952666.html