<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title>meisw's blog</title>
		<link>http://meisw.wdlinux.cn//</link>
		<description>工作,学习,生活,这里将会有一些记录.     备用域名:http://meisw.wdlinux.cn</description>
		<copyright>Copyright (C) 2004 Security Angel Team [S4T] All Rights Reserved.</copyright>
		<generator>SaBlog-X Version 1.6 Build 20080806</generator>
		<lastBuildDate>Sun, 31 May 2026 00:55:27 +0000</lastBuildDate>
		<ttl>30</ttl>
		<item>
			<guid>http://meisw.wdlinux.cn//show-969-1.html</guid>
			<title>ubuntu下从源码编译比特币(Bitcoin)客户端</title>
			<author>admin</author>
			<description><![CDATA[<pre class="prettyprint" name="code" style="white-space: pre-wrap; word-wrap: break-word; position: relative; overflow-y: hidden; overflow-x: auto; padding: 2px; border: 1px solid rgb(136, 136, 136); color: rgb(85, 85, 85); line-height: 28px; font-size: 16px; background-color: rgb(238, 242, 246);"><span class="pun" style="color: rgb(102, 102, 0);">./</span><span class="pln" style="color: rgb(0, 0, 0);">configure</span></pre>
<p><span style="color: rgb(0, 128, 0); line-height: 28px; font-family: &quot;Hiragino Sans GB W3&quot;, &quot;Hiragino Sans GB&quot;, Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: rgb(238, 242, 246);">运行完上边的这个命令之后，你就可以知道你的系统中都少什么库，下边就是安装缺少的库的方法</span><br style="color: rgb(85, 85, 85); line-height: 28px; font-family: &quot;Hiragino Sans GB W3&quot;, &quot;Hiragino Sans GB&quot;, Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: rgb(238, 242, 246);" />
<span style="color: rgb(85, 85, 85); font-family: &quot;Hiragino Sans GB W3&quot;, &quot;Hiragino Sans GB&quot;, Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; line-height: 28px; background-color: rgb(238, 242, 246);">If you encounter&nbsp;</span><span style="color: rgb(85, 85, 85); line-height: 28px; font-family: &quot;Hiragino Sans GB W3&quot;, &quot;Hiragino Sans GB&quot;, Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: rgb(238, 242, 246);">configure: error: libdb_cxx headers missing<br />
</span><span style="color: rgb(0, 128, 0); line-height: 28px; font-family: &quot;Hiragino Sans GB W3&quot;, &quot;Hiragino Sans GB&quot;, Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: rgb(238, 242, 246);">提示少libdb_cxx头，这个时候运行下边令命安装db的C++开发库</span><span style="color: rgb(85, 85, 85); line-height: 28px; font-family: &quot;Hiragino Sans GB W3&quot;, &quot;Hiragino Sans GB&quot;, Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: rgb(238, 242, 246);"><br />
</span><span class="pln" style="white-space: pre-wrap; background-color: rgb(238, 242, 246); font-size: 16px;">sudo apt</span><span class="pun" style="white-space: pre-wrap; background-color: rgb(238, 242, 246); font-size: 16px; color: rgb(102, 102, 0);">-</span><span class="kwd" style="white-space: pre-wrap; background-color: rgb(238, 242, 246); font-size: 16px; color: rgb(0, 0, 136);">get</span><span class="pln" style="white-space: pre-wrap; background-color: rgb(238, 242, 246); font-size: 16px;"> install libdb5</span><span class="lit" style="white-space: pre-wrap; background-color: rgb(238, 242, 246); font-size: 16px; color: rgb(0, 102, 102);">.1+</span><span class="pun" style="white-space: pre-wrap; background-color: rgb(238, 242, 246); font-size: 16px; color: rgb(102, 102, 0);">+-</span><span class="pln" style="white-space: pre-wrap; background-color: rgb(238, 242, 246); font-size: 16px;">dev</span>&nbsp;</p>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>
<pre style="white-space: pre-wrap; word-wrap: break-word; color: rgb(85, 85, 85); font-size: 16px;"><span class="pun" style="color: rgb(102, 102, 0);">./</span><span class="pln" style="color: rgb(0, 0, 0);">configure </span><span class="pun" style="color: rgb(102, 102, 0);">--</span><span class="kwd" style="color: rgb(0, 0, 136);">with</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">incompatible</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">bdb</span></pre>
</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-969-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2017-09-03 21:44</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-966-1.html</guid>
			<title>bitcoin-cli</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(68, 68, 68); font-family: &quot;Microsoft Yahei&quot;, SimSun, sans-serif;">用 sendfrom 函数，第一个参数指定账号，第二个参数指定发送地址，第三个参数指定发送金额，例如：</span><br style="word-wrap: break-word; color: rgb(68, 68, 68); font-family: &quot;Microsoft Yahei&quot;, SimSun, sans-serif;" />
<span style="color: rgb(68, 68, 68); font-family: &quot;Microsoft Yahei&quot;, SimSun, sans-serif;">bitcoin-cli sendfrom &quot;MyAccount&quot; &quot;1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd&quot; 0.01</span></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-966-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2017-07-25 22:00</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-957-1.html</guid>
			<title>以太坊生态系统中的工具和技术</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;http://ethfans.org/posts/tools-and-technologies-in-the-ethereum-ecosystem</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-957-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2017-06-06 22:09</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-920-1.html</guid>
			<title>新生代开源区块链技术</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">区块链的技术发展一日千里，几乎每天都有区块链技术或应用的新消息和进展，每个月都有新的区块链相关技术出来，各类区块链技术体系层出不穷，除了Elwin在《区块链主流开源技术体系介绍》提到的目前几大主流的开源区块链技术体系（包括比特币体系、以太坊、fabric、比特股、公证通、瑞波、未来币、锯齿湖、布比、小蚁等技术体系介绍，有兴趣可以搜索旧文看看）在不断完善发展外，市场上很快又涌现了很多新生代的区块链技术体系，本文将会一一进行介绍。</span></p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">一、恒星网络</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">恒星网络，stellar，一个由前瑞波(Ripple)创始人Jed McCaleb发起的区块链接项目，用于搭建一个数字货币与法定货币之间传输的去中心化网关。最近，乐视金融与恒星基金会签约，共建NBiLe与Lumens两个平行网络，实现通缩与通胀并行。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">恒星网络是基于Ripple基础上进行开发，在比特币和瑞波的技术基础上做了的很多改进，特别是相关的共识机制和验证算法，恒星网络运行节点性能得到提高，并节点资源需求非常低。众多改进其中，最大改动的是恒星支付系统的支撑算法SCP（恒星共识协议），号称是目前最安全的类拜占庭算法。SCP共识机制应用&ldquo;集合块&rdquo;，即各节点选择其可信任的其他节点。所有这些个体选择之和便是系统层面的共识集合。这些集合块将整个系统联结起来，正如个体网络的决策统一了互联网一样。SCP对计算能力以及经济成本消耗要求适度，降低了进入门槛并潜在地把金融系统开放给新的参与者，同时也是一种最佳的对抗恶性行为参与者使得系统恢复的构建方法。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">开源代码地址为<a target="_blank" href="https://github.com/stellar/stellar-core" style="color: rgb(51, 102, 153); text-decoration: none;">https://github.com/stellar/stellar-core</a>，系统主要开发语言为C++，共识机制为SCP，支持智能合约，适用于公链和联盟链。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">二、Tendermint</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">美国公司推出的Tendermint作为第二代区块链架构，已经超越了受限制的基于代币/类比特币的单片系统，是第一个实施分片技术的公共区块链。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Tendermint是一种开源的区块链套接字协议，消除了区块链之前的复杂性，为区块链开发提供了模块化结构，并且在区块链核心提供了一个开源的区块链引擎，使得各种机构和开发团队都能够轻松且高效地创建属于他们自己的区块链技术。Tendermint主核心将会管理所有的区块链分区，你可以有比特币分区或以太坊分区，具有很大的灵活性。在Tendermint平台上可以搭建基于任何编程语言的应用开发界面，主核心管理所有分片，分片包含很多类型，可以是比特币分片、或者以太坊分片。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Tendermint共识引擎通过Tendermint套接字协议（TMSP）与应用程序进行连接。Tendermint通过在应用程序进程和共识形成过程之间设置一个非常简单的应用程序接口，可以对区块链设计进行分解。并且TMSP不依赖于某一特定的编程语言，所以开发人员可以使用任意一种编程语言来编写智能合约。用户同样还能够利用现有的代码库，工作流和开发生态系统来创建复杂的应用程序。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">开源代码地址为<a target="_blank" href="https://github.com/tendermint/tendermint" style="color: rgb(51, 102, 153); text-decoration: none;">https://github.com/tendermint/tendermint</a>，系统主要开发语言为GO，所使用的是拜占庭容错共识机制，支持智能合约，具有去中心化控制、低延时、渐进安全的特效，大大提高扩展性和速度，每秒钟可以完成超过10,000笔交易，适用于公链和联盟链、私链。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">三、Openchain</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Openchain是由区块链技术公司Coinprism开源分布式总账区块链工具，主要提供给大型企业和金融机构，Openchain 在处理大型企业和金融机构的数据的时候，相较于传统的区块链工具，能大大的降低计算速度，并能降低成本和交易方风险。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">不同于比特币，Openchain基于一种独特的分布式账本技术，它可帮助用户部署自己版本的区块链，减少用户的交易成本和结算时间。Openchain去除了区块，交易和交易之间直接连通，这意味着交易可以得到即时确认。任何人都可以连接到一个验证的节点，并收到一份交易验证的实时复制本，Openchain还通过数字签名来保护交易的安全性，使交易不可伪造。另外，通过挂钩模块，基于Openchain的token可以作为侧链挂钩到比特币网络上。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">开源代码地址为<a target="_blank" href="https://github.com/openchain/" style="color: rgb(51, 102, 153); text-decoration: none;">https://github.com/openchain/</a>，系统主要开发语言为C#开发，他是DNX应用，可以支持跨平台运行，支持智能合约，适用于联盟链。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">四、多链MultiChain</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">多链Multichain，他是一个区块链软件平台，任何人都可以在上面创建和部署私链（permission chain）。隐私与控制的争议是比特币成为行业性金融机构的障碍，而用MultiChain创建的私有链则克服了这个困难。Multichain支持快速部署，两步就可以生成自已的区块链，三步就可以连接上其它区块链。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">MultiChain是采用PoW共识机制，通过对用户权限的综合管理解决了挖矿，隐私和公开性问题。MultiChain提供了一种创新性的可信决策网络实体的方法来解决私有区块链的挖矿问题。该平台可将挖矿活动限制在一套可供验证的实体内，并且避免了单一方对挖矿过程的垄断。这种被成为&ldquo;多样性挖矿&rdquo;的方案通过限定给定窗口内同一矿工的区块数量来解决挖矿问题。&ldquo;多样性挖矿&rdquo;取消了工作量证明的重要性和本地加密货币的必要性，并且可使处理交易的矿工以随机轮转的方式认可交易。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">MultiChain向后兼容比特币，因此用户能够把现存的比特币应用导入到 MultiChain。不是支持像比特币内核的单一链， MultiChain可被配置以同时支持同一网络的不同区块链。MultiChain能够支持很多第三方资产，能够使私有区块链和比特币区块链相互转换。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">MultiChain开源代码即将发布中。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">五、Corda</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">R3的区块链软件Corda，旨在为参与其中的70多家银行研发解决方案，专为金融服务所设计的新分散式的分类帐平台。他号称自己不是区块链，而用以记录和管理金融合约的分布式账本。但Elwin认为，Cordar的系统核心还是是基于区块链技术的，他包含区块链的五大特性，共识、有效性、唯一性、不可更改性和认证，Corda採用许多区块链技术的优势与特性，同时捨弃掉让区块链技术无法融进大多数金融领域的设计理念，排除了一些不适合银行业应用场景的设计思路。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Corda平台基于产业标准工具所打造，不包含原生虚拟货币，主要特性包括能可支援各种共识机制、自动编排跨组织之间的工作流，不需仰赖单一中心化的控制机构，Corda用非常精确的时间界限来处理交易而非区块挖掘时平均大致的时间界限，且能直接设计出负责监管与监督观察作业的节点，并经由特定交易方来验证，不需由一大群与该交易无关的验证者。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Corda在智能合约，数据处理等方面也做了创新，而且也符合通过协作以保持金融数据协议的准确和共享。自然隐私和监管也在它的专用平台设计之中。Corda关注可互操作性和增量部署，不对第三方泄露机密信息。公司可以查看与对手方达成的协议，并确保双方看到的信息一致并向监管机构报备。Corda系统引入了法律语言体系，并包含管理金融协议的作用，该系统必须使企业逻辑编写简单化并与现有代码兼容，还必须支持协议相关企业间的行为协调。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">针对金融使用场景和面向银行为主要使用者，Corda系统主要特点：</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 没有多余的全局数据共享：只有有合法需求的参与方可以按照协议获取数据；</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; Corda编写和配置在企业间流转，无中心控制者；</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; Corda在企业间单个交易水平达成共识，而不是在系统水平上；</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 系统设计直接支持监管观察员节点；</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 交易直接由交易双方验证，而不是由一大群不相干的验证者进行；</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 支持多种共识机制；</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 记录了智能合约代码和人类语言法律文件的清晰联系；</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 用行业标准工具创建；</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 没有原始加密货币。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Corda适用于联盟链，特别为金融业务打造，下个月将发布开源代码。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">六、龙链</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">龙链（Dragonchain）是迪士尼打造的，他是将其混合公有/私有区块链的区块链平台。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">龙链是另一种用来保持记录和处理交易的区块链。它与比特币的底层技术十分相似，但又有一点不同。龙链是一种多币制的区块链，节点就可以随之定义一种货币并支持其使用。该网络上可以同时使用多种货币。龙链的共识机制可以支持一种或多种现有的共识机制（Trust，PoW，PoS），甚至是可以支持自己定义和创建一种新的共识机制。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">龙链的目标特性：</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 易于集成现有的系统</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 便于传统的工程师和程序员开发，不一定需要熟悉的区块链、分布式系统和密码密码学技术</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; C/S客户服务器方式和RESTful方式集成</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 简单灵活的架构</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 默认情况下提供对业务数据的保护</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 允许业务集中控制过程</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 固定长度和周期，短和高速的区块</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 多货币支持</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 没有基础货币</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 与其他公共和私人blockchains的互操作性</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">开源代码地址为<a target="_blank" href="https://github.com/dragonchain/dragonchain" style="color: rgb(51, 102, 153); text-decoration: none;">https://github.com/dragonchain/dragonchain</a>，系统主要开发语言是<a href="http://lib.csdn.net/base/11" class="replace_word" title="undefined" target="_blank" style="color: rgb(223, 52, 52); text-decoration: none; font-weight: bold;">Python</a>，支持智能合约，适合联盟链和私链。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">七、量子链</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">量子链Qtum是中国社区原创的区块链公链。Qtum通过价值传输协议（Value Transfer Protocol）来实现点对点的价值转移，并根据此协议，构建一个支持多个行业的（金融、物联网、供应链、社交游戏等）去中心化的应用开发平台（DAPP Platform）。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">量子链的定位是，做一个符合行业监管的区块链去中心化应用开发平台。为了符合以后的行业监管，量子链团队在设计的时候，为监管者的角色设计了很多可选项，引入数字身份和第三方征信平台，设计一种新的合约类型&mdash;主控合约，把监管者的角色引入，同时监管者可以作为 Qtum系统中的喻言和数据源的提供者。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">量子链采用可插拔的共识机制：Qtum系统包括 Qtum 公链和Qtum联盟链，因为网络环境和参与者的不同，考虑到公链的去中心化程度、参与门槛、安全性和可靠性，量子链开发团队采用IPOS（Incentive Proof of Stake）机制作为区块链网络的共识机制。因为联盟链大多参与者都是受限的节点、身份已知的对手方，对共识机制的考量不同于公链网络，在联盟链中，量子链将采取Proof of Time 和Raft结合的共识协议，实现高速的区块链共识网络。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Qtum的开源代码地址Elwin未找到，支持EVM的虚拟机（EVM/EVM2.0），支持智能合约，适合公链和联盟链。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">八、Chain</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Chain是由一家刚成立两年的美国创业公司Chain推出，是一个企业级的区块链平台架构，可以让机构构造从零开始更好的金融服务。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">作为区块链供应商，Chain在过去的两年多时间中获得了极好的信用。Chain通过将专属区块链和分布式总账的源代码进行开放，可以让更多的人在其软件上增加应用或是建立专属网络。Chain核心开发者版本的创建花费了数年时间，它是区块链供应商和金融机构合作的直接产物。由于这个开源软件针对的是金融领域，因此它允许用户创建和发行他们自己认为合适的数字资产。</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">Chain 开放标准在以下方面实现突破：</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 全新的共识模型在不到一秒的时间里实现交易的最终完成，即便是交易量非常大也能支持</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 私密解决方案对区块链数据进行加密，并让相关对手方和监管者进行有选择的读取</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 智能合约框架和虚拟机支持简单的规则执行，以及进行键值存储的图灵完整程序</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 可伸缩的数据模型可以为网络参与者降低运行负荷</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">l&nbsp;&nbsp; 丰富的元数据层可支持满足KYC（了解你的客户）和 AML（反洗钱）要求</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">&nbsp;</p>
<p align="left" style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">开源代码地址为<a target="_blank" href="https://github.com/chain/chain" style="color: rgb(51, 102, 153); text-decoration: none;">https://github.com/chain/chain</a>，系统主要开发语言是GO，共识协议采用联邦拜占庭协议，支持多种数字资产，适合联盟链。</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-920-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2017-01-10 14:21</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-919-1.html</guid>
			<title>区块链共识小记</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">共识（Consensus）过程是一个非常有趣的过程。</span></p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">在我们的日常生活中，几乎所有的事情都是达成共识的过程。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">达成共识越分散的过程，其效率就越低，但满意度越高，因此也越稳定；相反，达成共识越集中的过程，效率越高，也越容易出现独裁和腐败现象。</p>
<ul style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">达成共识常用的一种方法就是通过物质上的激励以对某个事件达成共识；但是这种共识存在的问题就是容易被外界其它更大的物质激励所破坏。</span></li>
</ul>
<ul style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">还有一种就是群体中的个体按照符合自身利益或整个群体利益的方向来对某个事件自发地达成共识；当然形成这种自发式的以维护群体利益为核心的共识过程还是需要时间和环境因素的，但是一旦达成这样的共识趋势，其共识结果也越稳定，越不容易被破坏。</span></li>
</ul>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">在比特币和其它区块链币中，也存在如何达成共识的问题。或者说，<span style="box-sizing: border-box; font-weight: 700;">比特币或其它区块链币最核心的问题也是如何在去中心化的环境中达成共识。</span></p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">区块链是比特币背后的核心技术，也是支撑比特币的基础架构。因此在谈区块链共识，就必然要谈比特币的共识。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;"><span style="box-sizing: border-box; font-weight: 700;">比特币最核心的突破是在去中心化的情况下对交易事件达成了共识，即在没有中心组织的情况下对某个交易的有效性达成了一致。</span></p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">比特币实现这个共识的方法主要包括两个部分：</p>
<ol style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: border-box;">激励；即通过每个区块产生一定量的新比特币来激励参与者；</li>
    <li style="box-sizing: border-box;">引入外部资源确保安全；即通过大量的外部计算来确保共识的安全性，也就是工作量证明（Proof of Power）；</li>
</ol>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">这也是几乎所有PoW币种所采用的的方法。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">而这套方法要能持续长期运行下去的前提就是：</p>
<ol style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: border-box;">这种激励对参与者要有足够的吸引力；也就是说比特币要一直涨价，才能吸引参与者持续参与挖矿计算，以维护整个网络的运行；否则就会导致参与的人减少，破坏网络安全；</li>
    <li style="box-sizing: border-box;">没有外部攻击；由于比特币引入了外部计算来确保安全，因此只要有足够的挖矿算力（超过维护系统算力的51%）就能对系统成功进行攻击，这也是比特币长期存在的安全隐患之一；因为只要有钱，就能买到设备和算力。</li>
</ol>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">正是由于比特币存在的问题，例如消耗大量的资源、外部51%攻击等，出现了PoS（Proof of Stake）共识机理。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">总体上，PoS共识理论和实践目前仍处在探索阶段。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">最原始的PoS机理就是用股权代替PoW中的挖矿算力，来模拟比特币的挖矿过程。请注意，这个过程没有引入外部资源，而是仅仅依靠自身的币种股份来维护网络安全，因此其不需要消耗大量能源来进行计算；而且由于其没有引入外部的资源，因此不会担心外部攻击，例如外界的算力攻击。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">看起来PoS是很完美的，但是它存在一个严重漏洞。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">PoS存在内部的Nothing-at-Stake攻击。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">什么是Nothing-at-Stake（常写作N@S）攻击？</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">假设系统中出现了两个分支链，那么对于持有币的&rdquo;挖矿者&ldquo;来讲，最佳的操作策略就是同时在两个分支上进行&ldquo;挖矿&rdquo;，这样，无论哪个分支胜出，对币种持有者来讲，都会获得本属于他的利益，即不会有利益损失。而且由于不需要算力消耗，因此PoS中在两个分支上挖矿是可行的。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">这导致的问题是，只要系统存在分叉，&ldquo;矿工们&rdquo;都会同时在这几个分支上挖矿；因此在某个情况下，发起攻击的分叉链是极有可能成功的，因为所有人也都在这个分叉链上达成了共识；而且甚至不用持有51%的币量，就可以成功发起分叉攻击；</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">而这在PoW中是不可行的，因为挖矿需要消耗算力，矿工只能在一个分支上进行挖矿。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">第二个问题是重写历史攻击；即攻击者可以通过购买原始持有币种的账户来从头发起攻击，重新分叉一个区块链。因为原始的币种持有者可以将币转移至其它账户，因此他是可以在没有损失的情况下将原始账户出售给攻击者的。攻击者需要的就是有足够数量币的原始账户；当然了，这也只是概率问题，因为有可能原始账户持有者不会出售他们的账户，但是理论上确实存在这种攻击。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">第三个问题是，尽管PoS中的挖矿不用消耗算力，运行成本很低，但是也存在如何激励矿工的问题。因为一般的PoS系统是没有新币产生的，矿工只能赚取交易费，而且在交易费不高的情况下，对矿工的激励也是很有限的。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">当然了，也有很多PoS币种解决这个问题的办法就是持续的再产生新币来激励挖矿者，这导致的问题就是通胀。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">上述3个问题是PoS要解决的，尤其是N@S的问题尤为重要，因为如果没有其它约束机制，这种攻击是完全有可能实现的。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">从以上可以看出，无论是PoW还是PoS机理的共识过程，其必要条件有两个：</p>
<ol style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: border-box;">信息公开共享；</li>
    <li style="box-sizing: border-box;">个体参与；</li>
</ol>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">以现实为例，事件的信息越透明、所涉及到的人员参与度越高，最终形成的共识也就越稳定、越持久。这与区块链共识是一致的。</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">【参考阅读】</p>
<ul style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: border-box;"><a href="http://www.slideshare.net/ktoso/distributed-consensus-aka-what-do-we-eat-for-lunch" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">分布式共识</a></li>
    <li style="box-sizing: border-box;"><a href="https://www.reddit.com/r/Bitcoin/comments/2pvt1e/proof_of_work_proof_of_stake_and_the_consensus/" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">PoW vs PoS共识讨论</a></li>
    <li style="box-sizing: border-box;"><a href="https://docs.google.com/document/d/13_FSQ1Koq8uLvqTaSvZdb6OT2SpUZZq53vFiiDQj4qM/edit#" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">PoS共识机理研究</a></li>
    <li style="box-sizing: border-box;"><a href="http://www.peercointalk.org/index.php?topic=2976.msg27303#msg27303" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">N@S攻击不可行性</a></li>
    <li style="box-sizing: border-box;"><a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2393940" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">It will cost you nothing to kill a &nbsp;Proof of Stake &nbsp;crypto currency</a></li>
    <li style="box-sizing: border-box;"><a href="https://download.wpsoftware.net/bitcoin/pos.pdf" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">Bitcoin PoS</a></li>
    <li style="box-sizing: border-box;"><a href="https://blog.ethereum.org/2014/01/15/slasher-a-punitive-proof-of-stake-algorithm/" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">Ethereum PoS</a></li>
    <li style="box-sizing: border-box;"><a href="http://nxtwiki.org/wiki/Transparent_Forging" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">Nxt PoS</a></li>
    <li style="box-sizing: border-box;"><a href="https://bitshares.org/technology/delegated-proof-of-stake-consensus/" target="_blank" style="box-sizing: border-box; color: rgb(218, 68, 83); text-decoration: none; transition: all 0.3s; background-color: transparent;">DPoS of BitShares</a></li>
</ul>
<p style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: 'Microsoft YaHei', 'Microsoft YaHei'; font-size: 16px; line-height: 27.2px;">&nbsp;</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-919-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2017-01-09 22:24</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-917-1.html</guid>
			<title>区块链核心技术演进之路-共识机制演进(1)</title>
			<author>admin</author>
			<description><![CDATA[<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">一般而言，在介绍区块链时经常会提到两个例子：一是由古老的记账模式延伸到分布式账本，二是拜占庭将军问题（Byzantine Generals Problem）。使用分布式账本目的是让每个节点都能够验证交易，而拜占庭将军问题与账本的一致性有关，即本文要讨论的共识机制（Consensus）。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">区块链上的共识机制主要解决由谁来构造区块，以及如何维护区块链统一的问题，该问题的理论基础是拜占庭容错（Byzantine Fault-Tolerant，BFT）。BFT从上世纪80年代开始被研究，目前已经是一个被研究得比较透彻的理论，存在解的前提条件及具体实现都已有现成算法。不过本文不打算从BFT说起，因为要分析的是区块链共识机制的演进过程，而中本聪并没有采用BFT。其实在我研究比特币伊始，即便在理解了POW机制之后的很长一段时间内，并不了解拜占庭将军问题。后文分析 HyperLedger Fabric的PBFT以及小蚁项目的DBFT时再全面阐述拜占庭将军问题及传统分布式一致性算法（PAXOS、RAFT）。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">共识机制的核心是区块的构建和检验，POW系统构建区块的过程一般称为&ldquo;挖矿&rdquo;（mine），POS 系统PPC的区块构建方式一般称为&ldquo;铸造&rdquo;（mint），而NXT的区块构建方式一般称为&ldquo;锻造&rdquo;(forge)。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<h2 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 20px; margin-bottom: 10px; font-size: 24px; max-width: 100%;">POW</h2>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">共识机制在以前一般被称为证明方式（Proof），因为比特币采用工作量证明（即Proof-Of-Work，简写为POW）。随着大家对分布式账本一致性问题的不断探索，很多方法被提出来，尤其近期有很多区块链项目回归了对传统BFT算法的改进，在思路上已经跳出了&ldquo;证明&rdquo;的语义，因此进一步高度概括为共识机制。我记得第一次碰到工作量证明这一概念时感到很费解，对这种表述方式很头疼，掌握了POW机理后才真正明白，通俗讲就是&ldquo;通过工作以获得指定成果，用成果来证明曾经付出的努力&rdquo;。其实我们日常工作生活中经常使用工作量证明，比如学生考试成绩，毕业证以及驾照等，这种证明方式的一个显著特征是往往需要很大的工作量才能拿到指定成果，但这个成果很容易验证。因为我们一般很难去实时监督一个人是否真的付出了这些工作量，所以只能使用工作量的结果来证明。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">再回到比特币的设计思路，中本聪已经使用非对称密码解决了电子货币的所有权问题，用区块时间戳解决了交易的存在性问题，用分布式账本解决了剔除第三方结构后交易的验证问题，剩下需要解决的问题是双重支付，这要求所有节点账本统一，而真正的平等又必须赋予人人都有记账的权利，记账是一件简单的事情，每个人都可以做，显然最终会存在众多大同小异的账本，但我们只需要其中的一个账本就够了。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">中本聪想到给记账加入成本，总账本由各个分页按照时间先后排序，给每个账本分页设立一个评判标准，以区分账本分页是否合格，这给记账增加了难度，同时给每个账本分页加入一个随机元素，用以调节记账难度以保证一定时间段内只有一个人生成合格的账本分页。增加的成本就是工作量，合格的账本分页就是工作量证明。对于比特币而言，所谓的账本分页就是一个区块，区块通过巧妙设计形成区块链，合格的区块可以表述为：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">F(Nonce) &lt; Target</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">其中Nonce是随机元素，Target是合格区块的量化，每个记账节点的Target一致。此外POW的成功运行还需要配合如下两条约定，<br style="box-sizing: border-box; max-width: 100%;" />
Best chain原则：将最长的链条视为正确的链条。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">激励原则：找到合格的区块有奖励收益。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">第1条约定为硬性规则，无条件遵守，大家要么不玩，要玩就遵守这条原则，毕竟共同的目标是找到一致性账本，而最长的链条代表最大的工作量，如果没有这条约定，每个人都只会构造自己的区块链，无法统一。第2条为工作量激励，既然记账有成本，那唯有收益才能驱动大家都去记账，参与记账构造区块变成投资行为，其成本和收益风险在第1条约束下形成博弈，驱动所有节点按约定规则老老实实够造区块，最终达到纳什均衡。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">具体实现方式，比特币采用哈希（Hash）算法，关于哈希算法的原理和特点在前一篇文章（挖矿演进）已经详细讨论。逻辑上比特币是对整个区块进行哈希运算，但真正实现并非将整个区块数据作为哈希函数的参数，区块大体可分为区块链头和交易列表两部分，交易列表通过构造成Merkle树最终浓缩成Merkleroot内置于区块头，区块头只有6个字段，共80字节，如此设计首先带来的好处是方便哈希运算，每次运算只需要80字节的参数输入，而不是整个区块的数据，但交易列表的任何变化又能体现在哈希运行结果上。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><img class="aligncenter size-full wp-image-113138" alt="p1" src="http://7fvhfe.com1.z0.glb.clouddn.com/wp-content/uploads/2016/12/p13.png" width="462" height="481" style="box-sizing: border-box; border: 0px; vertical-align: middle; display: block; margin-left: auto; margin-right: auto; max-width: 100%; height: auto;" /></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">比特币采用SHA256哈希运算，且每次都是连续进行两次SHA256运算才能作为最终结果，前一次运算的结果作为后一次运算的输入，即Double SHA256，一般简称SHA256D，扩展上面的公式，比特币合格区块判断依据如下：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">SHA256D(nVersion,hashPreBlock,hashMerkleRoot,nTimes,nBits,Nonce)&lt;MAXTARGET/Diff</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">其中式子左边的6个参数（区块头）在前一篇文章已经解释，MAXTARGET为最大目标值，常量；Diff代表难度，全网难度一致。MAXTARGET/Diff即通常所说的当前目标值。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">很显然，POW的核心要义为：算力越大，挖到块的概率越大，维护区块链安全的权重越大。相对其他共识机制而言，POW逻辑简单，容易实现，容错达50%，其安全有严格的数学论证。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<h2 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 20px; margin-bottom: 10px; font-size: 24px; max-width: 100%;">POS</h2>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">POW并非完美，其中被指责最多的主要有两点，一是浪费能源，二是风险和收益博弈必然导致联合挖矿，而大算力矿池可能会对系统的去中心化构成威胁。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">于是在2011年，一个名为Quantum Mechanic的数字货币爱好者在Bitcointalk论坛提出Proof-of-Stake（POS）证明机制，该机制被充分讨论之后证明具有可行性。如果说POW主要比拼算力，算力越大，挖到一个块的概率越大，POS则是比拼余额，通俗说就是自己的手里的币越多，挖到一个块的概率越大。POS合格区块可以表述为：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">F(Timestamp) &lt; Target * Balance</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">与POW相比，式子左边的搜索空间由Nonce变为Timestamp，Nonce值域是无限的，而Timestamp极其有限，一个合格区块的区块时间必须在前一个区块时间的规定范围之内，时间太早或者太超前的区块都不会被其他节点接纳。式子右边的目标值引入一个乘积因子余额，可见余额越大，整体目标值（Target * Balance）越大，越容易找到一个区块。因为Timestamp有限，POS铸造区块成功率主要与Balance有关。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">POS只是代表一种共识机制理念，具体有多种实现方式，下面重点解析两种比较经典的实现思路。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<h3 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 20px; margin-bottom: 10px; font-size: 24px; max-width: 100%;">Peercoin</h3>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">Peercoin（点点币，PPC）于2012年8月发布，最大创新是其采矿方式混合了POW工作量证明及POS权益证明方式，其中POW主要用于发行货币，未来预计随着挖矿难度上升，产量降低，系统安全主要由POS维护。目前区块链中存在两种类型的区块，POW区块和POS区块。PPC的作者为同样不愿意公开身份的密码货币极客Sunny King，同时也是Primecoin的发明者。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">要掌握Peercoin的POS机制，需要重点理解Sunny King专门为PPC设计的几个核心概念：Coinstake，Kernel，Stake Modifier，Modifier Interval，Stake Reward，Coinage等。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">Coinstake</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">为了实现POS，Sunny King专门设计了一种特殊的交易，叫Coinstake，Coinstake的设计借鉴于中本聪的Coinbase设计。本质上Coinbase和Coinsake都是一笔交易，只是对他们的输入输出做了一些硬性限制。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">而Coinstake的设计又需要有别于Coinbase，这样才不会扰乱系统原有的POW机制，简单对比一下两者结构上的不同，</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><strong style="box-sizing: border-box; max-width: 100%;">Coinbase结构要求：</strong></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">输入数量必须等于1，且输入的prevout字段（指定前一笔交易的输出）必须置空值。<br style="box-sizing: border-box; max-width: 100%;" />
输出数量必须大于等于1。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><img class="aligncenter size-full wp-image-113139" alt="p2" src="http://7fvhfe.com1.z0.glb.clouddn.com/wp-content/uploads/2016/12/p23.png" width="866" height="443" style="box-sizing: border-box; border: 0px; vertical-align: middle; display: block; margin-left: auto; margin-right: auto; max-width: 100%; height: auto;" /></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><strong style="box-sizing: border-box; max-width: 100%;">Coinstake结构要求：</strong></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">输入数量大于等于1，且第一个输入的prevout字段不能为空，即要求Kernel必须存在。<br style="box-sizing: border-box; max-width: 100%;" />
输出数量大于等于2，且第一个输出必须置空值。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">这两种特殊交易在区块链中存放的位置也有特殊要求，中本聪规定每个区块的第一笔交易必须放置Coinbase，反之，Coinbase不能出现在区块的其他位置。Sunny King显然不想破坏这个规则，他增加了一条规则，对于POS区块，第二笔交易必须放置Coinstake，反之，Coinstake不能出现在其他地方。换言之，只要第二笔交易是Coinstake，那么这个区块就当POS区块来处理。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">Coinbase和Coinstake都不会被单独广播，而只存在于区块中，因此客户端节点一般都不允许进入内存池，当花费这两种交易时，都需要检测是否已经成熟。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;"><strong style="box-sizing: border-box; max-width: 100%;">Kernel Protocal</strong></h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">Coinstake的第一个输入(Input 0)叫Kernel，Kernel在POS机制里确实起到核心作用，合格区块的判定与之息息相关。PPC合格区块判断条件为：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">SHA256D(nStakeModifier + txPrev.block.nTime + txPrev.offset + txPrev.nTime + txPrev.vout.n + nTime)&lt; bnTarget * nCoinDayWeight</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">式子左边的每一个参数都有明确的设计目的，其中，</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">nStakeModifier</code>：专门为POS设计的调节器，按照以上公式，如果没有参数nStakeModifier，当一个人收到一笔币得到网络确认之后，他立即就能提前计算得知自己在未来何时可以锻造区块，这显然不符合设计目标，Sunny King希望POS矿工和POW矿工一样做盲目探索，以实时在线维护区块链，nStakeModifier的设计就是为了防止POS矿工提前计算。nStakeModifier可以理解为POS区块的一个属性，每一个区块对应一个nStakeModifier值，但nStakeModifier并不是每个区块都变动，不过协议规定每隔一定时间（Modifier Interval）必须重新计算一次，取值与前一个nStakeModifier以及最新区块哈希值有关，因此POS矿工无法提前计算，因为他不知道未来的区块哈希值。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">也就是说，在PPC系统中，除了存在区块链，币链（币的交易签名历史），还隐藏着一个很少被提及的链条&mdash;&mdash;权益调节器链条。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">值得一提的是，Sunny King是在PPC后来的版本才加入这个调节器的，一开始他使用nBits。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">txPrev</code>：Kernel对应的前一笔交易。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">txPrev.block.nTime</code>：txPrev所在区块的时间戳，一笔交易被纳入区块的时间是交易发起者不能确定的，节点有可能通过提前计算预估到未来对自己有利的时间戳，这个参数就是为了防止节点利用这种预估优势提前生成大批交易。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">txPrev.offset</code>：txPrev在区块中的偏移量，用以降低网路节点同时生成coinstake的概率。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">txPrev.nTime</code>：txPrev构造时间，设计目标如txPrev.offset。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">txPrev.vout.n</code>：Kernel在txPrev中的输出下标，设计目标如txPrev.offset。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">再看等式右边，<br style="box-sizing: border-box; max-width: 100%;" />
<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">bnTarget</code>：全网当前目标难度基准值，类似POW中的当前难度值，由nbits记录。<br style="box-sizing: border-box; max-width: 100%;" />
<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">nCoinDayWeight</code>：Kernel的币龄。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">由以上式子可知，Sunny King一方面希望能给POS矿工提供充足的随机性，另一方面搜索空间严格局限于Coinstake的时间戳字段，以保证影响找到合格区块链的最大因素是Kernel的币龄。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">节点在锻造区块时，首先从自己所有的UTXO中选定一个作为Kernel，构造coinstake，计算hash,如果不合格，重新构造coinstake，重构时时间戳Time会改变，也可以改变Kernel，以得到不同的Coinstake，如此往复，直到找到合格区块。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">Coinage</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">上面提到了币龄，也叫币天，假如1.5个币存在于区块链中10天，币龄数值为：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">Coinage = 1.5*10 = 15</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">PPC采用币龄，而不是直接采用余额（Balance）来计算。一个UTXO一旦被花费，其币龄被清零，新的UTXO币龄从0开始算起。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">stakeReward</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">权益激励，俗称获得利息，计算公式如下：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">stakeReward = nCoinAge * 33 / (365 * 33 + 8) * 0.01 * COIN</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">公式可简化为：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">stakeReward = (0.01 * nCoinAge / 365) * COIN</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">其中nCoinAge是Coinstake所有输入的币龄总和，由公式可知收益按1%年率计算。理想状态下，假设所有的币全年都参与挖矿，代币总量每年有1%通胀率，这一设计为很多人所诟病，而且，这一设计并不能激励矿工积极参与挖矿以维护区块链的安全，因为如果不考虑手续费，持币用户每隔几个月打开节点铸币，或者实时在线铸币，理论上收益都是一样的。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">stakeMinAge</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">POS系统也存在51%币龄攻击风险，为了增加攻击难度，Sunny King对每一笔UTXO的铸币资格做了最小年龄（stakeMinAge）限制：一个UTXO在区块链存在的时间小于stakeMinAge则没有铸币资格，PPC最小币龄为8小时。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">后来有些竞争币种加入了最大年龄（stakeMaxAge）限制：一个UTXO在区块链存在的时间大于stakeMaxAge则币龄始终按stakeMaxAge计算。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">在Sunny King设计的POS机制中，一笔UTXO就像是一个矿工，该矿工每成功铸造一个区块后必须休息一段时间，因此，整套系统必须保证足够多的&ldquo;矿工&rdquo;同时在线铸造区块，才有可能获得平滑的出块速度。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<h3 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 20px; margin-bottom: 10px; font-size: 24px; max-width: 100%;">Nextcoin</h3>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">2013年9月，一个名为BCNext的用户在Bitcointalk论坛发起一个帖子，宣布将发行一种全新的纯POS币种，后来取名为Nextcoin，简称NXT。与当时其他山寨币直接Fork自Bitcoin源码的开发思路不同，BCNext另起炉灶，采用JAVA语言从头开发NXT，并对区块结构，交易结构，非对称密码等做了很多改进。NXT有很多创新点，这里只讨论其中最重要的创新&mdash;&mdash;透明锻造（Transparent Forging）。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">NXT的POS实现方式与PPC完全不同，合格区块判定方法为：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">hit &lt; baseTarget * effectiveBalance * elapseTime</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">其中，<br style="box-sizing: border-box; max-width: 100%;" />
<span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">hit</span>：<br style="box-sizing: border-box; max-width: 100%;" />
NXT抛弃中本聪的UTXO设计方案，采用账户（Account）余额方案，每一个账号对应一个私钥。每一个区块都有一个生成签名（generationSignature）字段，hit的生成与这个字段有关。当用户需要锻造区块时，首先计算自己独一无二的hit，计算过程如下：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">用户用自己的私钥对上一个区块的generationSignature进行签名，获得自己本区块的generationSignature。<br style="box-sizing: border-box; max-width: 100%;" />
对上一步结果进行SHA256运算，得hashdata。<br style="box-sizing: border-box; max-width: 100%;" />
取hashdata的前8个字节（共64比特位）作为hit变量。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">生成签名的设计有点类似于PPC的stakeModifier，也就是说，NXT区块链下隐藏着一个签名链条。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">式子右边，<br style="box-sizing: border-box; max-width: 100%;" />
<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">baseTarget</code>：全网难度基准值，这个难度按照每分钟一个区块目标调节。<br style="box-sizing: border-box; max-width: 100%;" />
<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">effectiveBalance</code>：账户有效余额，一笔币转到账户需要足够多的确认才有铸币权利，叫有效余额。<br style="box-sizing: border-box; max-width: 100%;" />
<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 16.2px; padding: 2px 4px; color: rgb(199, 37, 78); white-space: nowrap; border-radius: 4px; max-width: 100%; background-color: rgb(249, 242, 244);">elapseTime</code>：当前时间与上一个区块时间间隔，按照currentTime-lastBlockTime计算。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">分析以上式子，如果依然将式子左边视为挖矿，右边视为目标值，可知用户压根就没有搜索空间，因为当全网产生一个最新区块时，对于锻造下一个区块，每个用户自身的hit就固定了。式子右边，每个用户的目标值与自身的账户有效余额成正比关系，而且，随着时间往前推移，目标值不断变大，不等式最终一定会成立，即理论上每个节点都可以挖那个区块，但规定优先选择最早生成的区块。<br style="box-sizing: border-box; max-width: 100%;" />
<img class="aligncenter size-full wp-image-113140" alt="p3" src="http://7fvhfe.com1.z0.glb.clouddn.com/wp-content/uploads/2016/12/p32.png" width="847" height="492" style="box-sizing: border-box; border: 0px; vertical-align: middle; display: block; margin-left: auto; margin-right: auto; max-width: 100%; height: auto;" /></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">用上图类比NXT的锻造机制，每个圆柱体自身高度（hit）是固定的，假设限高杆不断升高（目标值target随着时间不断增大），最终所有圆柱体都能通过（合格区块），但高度最矮的圆柱体可以率先通过。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">节点段造区块流程为：账户必须实时在线，当全网有最新区块产生时，每个账户立即计算自己对应的hit，然后根据公式elapseTime = hit/(baseTaret * effectiveBalance)计算得知自己锻造区块的期望时间值，并将这个期望时间广播给网络其他节点，如此，全网每个节点都知道其他节点的期望时间，从而也就得知下一个区块优先由谁来锻造。账户在自己的时间窗口锻造好区块并立即广播全网，其他节点检验一个新区块是否有效，首先要检验证区块的生成签名是否有效，还要检验新区块的时间戳是否与产生区块的节点之前发布的期望时间吻合。每次客户端检测到网络中有新的区块产生，都会重新计算自己的期望时间并向全网发布。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">因为hit是用户用自己的私钥签名的结果，因此对于不同用户来说具有很大随机性，即便余额很少的用户，如果运气足够好，hit值很小，也有可能快速锻造区块。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">NXT区块的生成完全摒弃了竞争的理念，有点&ldquo;上帝早已安排好一切&rdquo;的味道，下一个区块由谁来生成冥冥中早就注定了，全网节点能做的就是静静等待那一刻的到来。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;"><img class="aligncenter size-full wp-image-113141" alt="p4" src="http://7fvhfe.com1.z0.glb.clouddn.com/wp-content/uploads/2016/12/p41.png" width="866" height="317" style="box-sizing: border-box; border: 0px; vertical-align: middle; display: block; margin-left: auto; margin-right: auto; max-width: 100%; height: auto;" /></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">如图，如果节点A没有在自己的锻造时间窗口内广播区块怎么办，没问题，网络会等B的区块，但是如果A和B间隔不远，或者由于网络传输原因部分节点先收到A的区块，部分节点先收到B的区块呢，网络就分叉了，此时Bestchain的原则依然是首选最长的链条，长度一致的分支，优先选择最高区块时间戳最小的分支。那如果节点对所有分支都锻造并广播区块呢，那就变成了一种攻击行为，网络最新区块附近的分叉会加剧。缓解问题的办法是让节点只挖最优分支，这一点没法体现在协议中，只能依靠诚实节点的自律。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">摒弃了竞争的理念，NXT共识不得不高度依赖于时间轴，节点虽可预知自己在未来何时可生成区块，但必须要等到那个时候才能广播区块，如果节点提前广播，网络其他节点将不会接受，BCNext在客户端实现上做了限制：对于最新区块，客户端只接受本机当前时间前后15秒范围内广播的区块，这种限制也没法体现在协议上，只能依靠客户端实时辅助实现。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">也难怪，NXT代币全部预挖，如果采用类似比特币那样由矿工慢慢发行模式，免不了竞争段造区块，而一旦竞争，区块链将立即陷入分叉。NXT整套共识规则的成功运行其实背后有一个潜在的利益博弈，即，持币者就是系统使用者，也是系统的受益者，大家应该联合起来共同维护区块链，做一个诚实的节点。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">也许你会想到一种攻击方法：即便手里持币量很少，但可通过生成大批账号并往每个账号转少量币，以每次都能找到很小的hit，也能快速锻造区块，如此一来POS就退化到类似POW的尴尬境地。BCNext首先从非对称签名算法下手，采用ED25519代替比特币的ECDSA，前者的计算难度比后者大。此外成熟期提高到1440个区块（1天），即一个账号有效余额一旦成功锻造一个区块，该部分余额需要等1天才能重新获得锻造资格。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">短暂的分叉还是不可避免的，NXT最新区块附近会有很多分支，一笔交易需要多一些确认才足够安全，NXT官方推荐10个确认。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<h2 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 20px; margin-bottom: 10px; font-size: 24px; max-width: 100%;">POS2.0</h2>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">PPC的成功运行很快就吸引了一批追随者，其中较为出名的包括新星币(Novacoin，NVC)、黑币（blackcoin，BLK）等。黑币社区认为币龄可能会被恶意的节点滥用以获得更高的网络权重并成功实施双花攻击，于是发布POS2.0白皮书，对PPC做了几个细节优化，解决了一些潜在的安全问题，其中最重要的改进是用余额代替币龄，合格区块的条件由：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">F(Timastamp) &lt; Target * 币数 * 币的年龄</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">变为：</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px; text-align: center;"><span style="box-sizing: border-box; max-width: 100%; color: rgb(255, 0, 0);">F(Timastamp) &lt; Target * 币数</span></p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">如此一来，一笔UTXO无论放置多久其锻造区块的能力不变，此举可激励节点必须更多的保持在线进行铸币，提高系统安全性，将攻击途径减少到最低限度，并且能够显著提高网络保持运行的节点数量。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<h2 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 20px; margin-bottom: 10px; font-size: 24px; max-width: 100%;">POS3.0</h2>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">黑币社区后来进一步升级，推出POS3.0版本，对交易手续费，难度调整做了一些优化，其中最显著的改变是将1%年利率奖励机制变为固定数额奖励（每个区块固定奖励1.5BLK），此举不但降低代币通胀率（考虑到会有代币永久丢失，低额奖励机制回归总量恒定的设计思路），同时意味着持币节点必须实时在线才能获得收益。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<h2 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 20px; margin-bottom: 10px; font-size: 24px; max-width: 100%;">DPOS</h2>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">比特股（Bitshares）项目于2013年8月开始启动，这是一个野心勃勃的项目，对区块链做了很多改造，并引入许多新概念和特征，尤其令人眼花缭乱的 Bitshares X、多态数字资产交易平台、资产锚定等新名词，一时令人无比兴奋而又困惑。此时POW和POS都已成功运行许久，彼此优劣已被反复讨论，两大阵营时至今日依然争论不休。按照项目规划，比特股对交易容量和区块速度有极高要求，显然POW或POS都达不到要求，于是比特股发明了一种新的共识机制&mdash;&mdash;Delegated Proof-Of-Stake（DPOS），即股份授权股权证明。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">DPOS很容易理解，类似于现代企业董事会制度，比特股系统将代币持有者称为股东，由股东投票选出101名代表，然后由这些代表负责产生区块。那么需要解决的核心问题主要有：代表如何被选出，代表如何自由退出&ldquo;董事会&rdquo;，代表之间如何协作产生区块等。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">持币者若想成为一名代表，需先拿自己的公钥去区块链注册，获得一个长度为32位的特有身份标识符，用户可以对这个标识符以交易的形式进行投票，得票数前101位被选为代表。<br style="box-sizing: border-box; max-width: 100%;" />
代表们轮流产生区块，收益（交易手续费）平分。如果有代表不老实生产区块，很容易被其他代表和股东发现，他将立即被踢出&ldquo;董事会&rdquo;，空缺位置由票数排名102的代表自动填补。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">从某种角度来说，DPOS可以理解为多中心系统，兼具去中心化和中心化的优势。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<h2 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 20px; margin-bottom: 10px; font-size: 24px; max-width: 100%;">总结</h2>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">&nbsp;</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">最后从几方面来简单对比分析以上几种共识机制的优劣和特点：</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">安全性</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">POW的安全性存在完整的数学证明，这一点是POS和DPOS无可比拟的优势。区块链共识机制一般要同时考虑抵御DDOS攻击和双重支付攻击，POW存在51%算力攻击威胁，比特币目前超强的算力使得破坏该系统需付出巨大代价。POS也会存在51%币龄攻击，而DPOS安全性完全取决于代表的诚实程度。NXT理论可以实现快速交易，但需要锻造节点曝光自己的IP，如此一来容易成为DDOS攻击对象，DPOS的代表也容易成为DDOS攻击对象。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">环保性</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">在不可能三角理论（去中心化，安全，环保不能同时兼备）中，POW彻底抛弃节约能源的需求，通过巨大算力来维护系统安全和去中心化特征。POS和DPOS几乎不费多余电力，但不可避免在另外两个特性做出牺牲。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">共识速度</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">POW很难缩短区块时间，POS相对而言可以缩短区块时间，尤其NXT会比PPC的实现方式更快，DPOS也可以在很短时间内达成共识，比特股目前30秒产生一个区块。不过POS更容易产生分叉，尤其NXT，所以交易需要等更多确认才被认为安全。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">交易容量</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">这是区块链未来发展需要解决的核心问题，巨大的交易容易意味着巨大的带宽和存储空间，POW的交易容量很难扩展，而NXT由于每个节点都可以预知下一个区块由谁锻造，可以直接将交易发给锻造节点，因此NXT交易容量有很大扩展性。从某种角度来说，DPOS可以理解为多中心系统，兼具去中心化和中心化的优点，如果代表节点都运行强大的服务器且彼此带宽足够大，理论上交易处理能力可比拟传统中心化系统，比如Visa。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">出块平滑度</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">POW由于哈希算法特性，可以得到平滑出块速度，而且可以间隔一段时间再调整全网难度，POS出块主要与余额有关，而用户余额差距梯度比较大，所以POS一般每个块都要调整全网基础难度。DPOS依靠有限代表人的协同作用，如果代表人不会频繁进出，几乎可以做到固定死出块间距。</p>
<h4 style="box-sizing: border-box; font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-weight: 500; line-height: 1.1; color: rgb(85, 85, 85); margin-top: 10px; margin-bottom: 10px; font-size: 20px; max-width: 100%;">最终性</h4>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">POW和PPC通过竞争达成共识，不存在最终性，理论上如果有足够算力，现在可以从头挖比特币区块链，不过可以依靠检测点实现最终性。NXT和DPOS严格依赖时间轴，依靠节点实时在线检测，所以存在最终性。</p>
<p style="box-sizing: border-box; margin-top: 5px; margin-bottom: 20px; max-width: 100%; word-break: normal; color: rgb(85, 85, 85); font-family: 'Microsoft YaHei', 'Helvetica Neue', ​Helvetica, ​Arial; font-size: 18px; line-height: 30px;">综合各方优势，个人认为POW适合应用于公链，如果搭建私链，因为不存在验证节点的信任问题，可以采用POS比较合适，而联盟链由于存在不可信局部节点，采用DPOS比较合适。</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-917-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-22 18:08</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-915-1.html</guid>
			<title>区块链技术方案研究与分析</title>
			<author>admin</author>
			<description><![CDATA[<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">作者：电子商务与电子支付国家工程实验室研究员 于镳、刘为怀</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">一、块链是什么</strong></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">区块链最初是由一位化名中本聪的人为比特币（一种数字货币）而设计出的一种特殊的数据库技术。<br style="box-sizing: inherit;" />
从数据的角度来看，区块链是一种把区块以链的方式组合在一起的数据结构，它能够使参与者对全网交易记录的事件顺序和当前状态建立共识。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">区块链概括起来是指通过去中心化和去信任的方式集体维护一个可靠数据库的技术。区块链涉及的技术关键点包括：去中心化、去信任、集体维护、可靠数据库、时间戳、非对称加密等。<br style="box-sizing: inherit;" />
区块链重新定义了网络中信用的生成方式，在系统中，参与者无需了解其他人的背景资料，也不需要借助第三方机构的担保或保证，区块链保障了系统对价值转移的活动进行记录、传输、存储，其最后的结果一定是可信的。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">二、区块链技术现状</strong></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">比特币之后，多元化区块链共同发展，经过了近8年的发展与实践，人们对区块链技术的了解越来越深入，也在让区块链技术与自身需求更契合的过程中逐渐明白了以下两点：（1）区块链技术本质上是互联网协议的底层技术，是互联网数据层次的技术；（2）区块链倡导的&ldquo;去中心&rdquo;并不是反中心，而是分中心（最彻底的分中心就是每个节点自己成为自身的中心）。因此，许多领域试图在比特币区块链的基础之上对其做进一步的改进。目前，区块链已经从比特币完全去中心化的公共区块链，发展出了依附于公有链之上的侧链以及非完全去中心化的私有区块链等。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">区块链技术处于理论阶段，尚需实践。区块链技术是伴随比特币的产生而出现的，目前最成熟的区块链就是比特币的区块链。国内外对于区块链技术的投入使用都已经逐渐展开，但目前尚未有完全落地的应用性成果展现出来。从发展的角度来看，区块链技术目前仍然处于理论阶段，今后的技术转换尚需一段很长时间的实践。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">三、区块链共识机制</strong></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">共识机制的作用是为了确认区块链上交易的有效性，目前常见的共识机制有POW工作量证明、POS权益证明、DPOS股份授权证明、Ripple共识机制以及PooL验证池，这几类共识机制各有优劣，应用场景也各不相同，下表展示了从不同维度对这几类共识机制的分析比较：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://upyun-assets.ethfans.org/uploads/photo/image/9ebc1db2df7741668ec18e56fd1c3eca.png" title="" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">POW（Proof of work）</li>
</ul>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">POW即工作量证明，就是众所周知的挖矿，它是一种竞争共识，通过工作量的证明来获得生成区块的权力。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">它的优点是完全的去中心化，各个节点完全平等，而且可以自由的进出；缺点则是POW会造成大量的挖矿资源浪费，达成共识的周期也比较长。</p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">POS（Proof of Stake）</li>
</ul>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">POS即权益证明，是POW的一种升级共识机制，它主要解决了POW工作量计算浪费的问题。当前POS已有很多不同的变种，但基本还是根据每个节点所占有代币的数量和时间（即权益）来决定其挖矿的难度。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">它的优点是缩短了各个节点之间达成共识的时间，缺点则是同POW一样仍然需要挖矿，并且POS会使得&ldquo;富者更富&rdquo;。</p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">DPOS（Delegate Proof of Stake）</li>
</ul>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">DPOS即股份授权证明机制，是POS的一个变种。它的原理是让每个持有代币的人进行投票，由此产生一定数量的&ldquo;超级节点&rdquo;，由这些节点来轮流产生区块。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">它的优点是不再需要通过挖矿来产生区块，从而可以大幅缩小交易确认的时间，能够达到秒级的共识验证，缺点则是DPOS还是得依赖于代币，不适用于一般的商业应用。</p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">Ripple Consensus（瑞波共识机制）</li>
</ul>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">Ripple Consensus是一种数据正确性优先的网络交易同步机制，它是基于特殊节点列表达成的共识。在这种共识机制下，必须首先确定若干个初始特殊节点，如果要新接入一个节点，必须获得51%的初始节点的确认，并且只能由被确认的节点产生区块。因此，它区别于前面几类共识机制的主要因素是有一定的&ldquo;中心化&rdquo;。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">Ripple Consensus的优点是能保证任何时候都不会产生硬分叉，并且交易能被实时的验证；而缺点则是新加入节点要取得与其他节点的共识所需时间较长。</p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">POOL验证池</li>
</ul>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">POOL验证池是基于传统分布式一致性算法加上数据验证的机制，也是目前行业链大范围在使用的共识机制。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">它的优点是无需建立代币，在成熟的分布式一致性算法（Pasox、Raft）的基础上，能够实现实时共识验证；缺点是性能会随着节点数的增加而变差，并且去中心化程度不够。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">除了常见的以上所述的几类共识机制，在区块链的实际应用过程中，还存在着五花八门的依据业务逻辑自定义的共识机制，如小蚁的&ldquo;中性记账&rdquo;、类似Ripple Consensus的Stellar共识机制、Factom等众多以&ldquo;侧链&rdquo;形式存在的共识机制等。<br style="box-sizing: inherit;" />
因此，本文依据共识机制的特性及典型性将其划分为三大类：POW、非POW以及侧链。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">四、区块链技术方案分析</strong></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">区块链技术发展到今天，已经从最初的数字货币领域扩展到社会领域的方方面面，各种各样的区块链技术方案不断涌现出来。通过对市场上现有的区块链技术方案进行研究，从共识机制、区块链使用方式两个维度对区块链技术方案进行分类，并根据技术影响力决定面积大小、技术成熟度决定颜色深浅对各个区块链技术方案进行绘制，分类结果如图1所示。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://upyun-assets.ethfans.org/uploads/photo/image/4e4552af9f83450c8070e9113ce2795b.png" title="" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /><br style="box-sizing: inherit;" />
图1 区块链技术方案分类&nbsp;<br style="box-sizing: inherit;" />
图1中，对15个区块链技术方案进行分类，其中，将共识机制划分为PoW、非PoW、侧链三个方面，区块链使用方式分为开源项目、商业解决方案、区块链云服务、现有区块链四种方式，技术影响力按面积大小进行区分，面积越大影响力越大，技术成熟度按颜色深浅进行区分，颜色越深技术越成熟。<br style="box-sizing: inherit;" />
从图1中可以看出，比特币、以太坊、HyperLedger三种区块链技术方案的技术成熟度最高，影响力最大，下面分别介绍这三种区块链技术方案。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">1比特币<br style="box-sizing: inherit;" />
比特币的概念最初由中本聪在2009年提出，根据中本聪的思路设计发布的开源软件以及建构其上的P2P网络。比特币是一种P2P形式的数字货币。点对点的传输意味着一个去中心化的支付系统。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">与大多数货币不同，比特币不依靠特定货币机构发行，它依据特定算法，通过大量的计算产生，比特币使用整个P2P网络中众多节点构成的分布式数据库来确认并记录所有的交易行为，并使用密码学的设计来确保货币流通各个环节安全性。P2P的去中心化特性与算法本身可以确保无法通过大量制造比特币来人为操控币值。基于密码学的设计可以使比特币只能被真实的拥有者转移或支付。这同样确保了货币所有权与流通交易的匿名性。比特币与其他虚拟货币最大的不同，是其总数量非常有限，具有极强的稀缺性。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">2以太坊<br style="box-sizing: inherit;" />
以太坊是一个专注于智能合约应用的数字货币和区块链平台，它的去中心化技术使交易摆脱了停机和审查的麻烦，解决了传统合约的纠纷等棘手问题，并且还能避免欺诈和第三方的干扰。以太坊的目标就是提供一个带有内置的成熟的图灵完备语言的区块链，用这种语言可以创建合约来编码任意状态转换功能，用户只要简单地用几行代码来实现逻辑，就能够创建各种满足需求的系统。<br style="box-sizing: inherit;" />
从技术架构角度看，以太坊是一个与底层区块链和协议无关的通用分布式运用开发平台和编程语言，包括数字货币以太币（Ether）和以太脚本（EtherScript），用于构建和发布分布式应用。它具备开放通用的特性，且内置有图灵完备虚拟机，可以运用任何货币、协议和区块链。网络上的每一个节点都可以运行以太坊虚拟机来发布分布式智能合约程序。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">以太坊有自己的分布式系统：包括文件服务Swarm、信息传输Whisper和信誉担保。Swarm是个去中心化文件服务；Whisper是加密通信传输系统；信用担保提供去信任网络中建立信誉和降低发现的系统，可以由第三方提供。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">此外，以太坊本身也是开源软件，具备了开源项目的快速创新特性，通过代码共享让新的项目可以快速的迭代出符合市场需求的产品。目前，以太坊正被一些金融机构、银行财团（比如 R3），以及类似三星、Deloitte、RWE 和 IBM 这类的大公司所密切关注，由此也催生出了一批诸如简化和自动化金融交易、商户忠诚指数追踪、旨在实现电子交易去中心化的礼品卡等等区块链应用。<br style="box-sizing: inherit;" />
以太坊两年来得到了技术社区和商业机构的大力支持，发展迅速，未来很有可能会成为区块链领域最具竞争力的解决方案之一。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">3HyperLedger<br style="box-sizing: inherit;" />
Hyperledger是一个由Linux基金会管理的开源区块链项目, 由IBM、Intel、埃森哲、JP摩根等公司领衔参与。HyperLedger被定义为：负责协调多个客户端的服务数据和低层次的&ldquo;沟通和共识层&rdquo;，一个致力于提高全球金融基础设施的&ldquo;数据骨干&rdquo;。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">Hyperledger利用了和比特币相同的UTXO/script 交易决策，并根据金融服务所需要的功能进行了扩展,HyperLedger提供了一种替代POW的共识机制，是一个带有可插拔各种功能模块架构的区块链实施方案，它的目标打造成一个由全身会来共同维护的一个超级账本。是允许将数据骨干理念扩展到多个组织层,作为全新金融基础设施的重要组成部分。</p>
<p style="box-sizing: inherit; margin-bottom: 0px; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">为了解决不同的业务问题，区块链技术方案的侧重点也不尽相同，因此，从去中心化程度、交易确认时间、是否有挖矿费、是否支持编程、是否全节点记账、私钥丢失是否造成用户财产损失、开源程度等几个方面对现有的区块链技术方案进行汇总，具体分析结果见下表。<br style="box-sizing: inherit;" />
<img src="http://upyun-assets.ethfans.org/uploads/photo/image/5ae80080dbcb481fb4bd9f59c181cffe.png" title="" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-915-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-21 23:45</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-908-1.html</guid>
			<title>Hyperledger fabric中的几个重要的角色</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">Application Backend</span></p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">存在的目的:<br />
&nbsp;&nbsp; &nbsp;后端应用程序服务支持应用程序关联到移动设备或者浏览器<br />
关键角色：<br />
&nbsp;&nbsp; &nbsp;1）通过成员服务管理末端使用者和注册者<br />
&nbsp;&nbsp; &nbsp;2）启动交易请求，发送请求到末端<br />
Owned by<br />
&nbsp;&nbsp; &nbsp;Solution provider, Network Proprietor</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&nbsp;</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">NVP节点</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">存在的目的：<br />
&nbsp;&nbsp; &nbsp;构建交易并且将它们发送到VP节点，peer节点保存了一份所有交易的副本以便于solution providers能够在本地查询它们<br />
关键角色：<br />
&nbsp;&nbsp; &nbsp;1.管理或者维护通过成员服务发行的用户证书<br />
&nbsp;&nbsp; &nbsp;2.构建交易并且将交易转发到VP节点<br />
&nbsp;&nbsp; &nbsp;3.维护一个本地账本，允许application owner查询当地的信息<br />
Owned by:<br />
&nbsp;&nbsp; &nbsp;Solution Provider, Network Auditor<br />
<br />
VP节点<br />
存在的目的:<br />
&nbsp;&nbsp; &nbsp;创建并且确认交易事物，并且维护chaincode的状态<br />
关键角色：<br />
&nbsp;&nbsp; &nbsp;1）管理并且维护被成员服务发布的用户证书<br />
&nbsp;&nbsp; &nbsp;2）创建交易<br />
&nbsp;&nbsp; &nbsp;3）在区块链网络上和其他VP节点一起执行交易<br />
&nbsp;&nbsp; &nbsp;4）维护本地账本副本<br />
&nbsp;&nbsp; &nbsp;5）参与共识并且更新账本<br />
Owned by:<br />
&nbsp;&nbsp; &nbsp;Network proprietor, Solution provider</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">membership（在未来的1.0版本中将变成cop）<br />
存在的目的：<br />
&nbsp;&nbsp; &nbsp;末端用户或者组织的身份发行与管理<br />
关键角色：<br />
&nbsp;&nbsp; &nbsp;1）发行登记证书给各个末端使用者或者组织<br />
&nbsp;&nbsp; &nbsp;2）发行交易证书到关联的各个末端使用者<br />
&nbsp;&nbsp; &nbsp;3）发行TSL证书确保在HyperLedger Fabric之间通信<br />
&nbsp;&nbsp; &nbsp;4）发行链特别的Key<br />
Owned by: Third Party service provider</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">注：目前我们使用的HyperLedger fabric是0.6版本，与将要发布的1.0版本相比较，Fabric有以下变动：<br />
1)HyperLedger Fabric v1.0 membersrvc模块将独立出来成为新的COP模块。<br />
&nbsp;&nbsp; &nbsp;COP将为Hyperledger fabric提供一个类似警方的安全功能<br />
&nbsp;&nbsp; &nbsp;COP的代码将比membership servicev0.6版本更短更简单<br />
2)HyperLedger Fabric v1.0将更具有安全性和扩展性，COP的独立出来将更使基于HyperLedger Fabric改造更简单。<br />
3)交易加密方面也将比v0.6版本加强很多，例如供应链, FOREX market, 健康医疗方面交易更加安全</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-908-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-21 11:32</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-907-1.html</guid>
			<title>Hyperledger fabric配置node.js</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">一、配置Swagger-UI</span></p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">1.你可以使用本地的node.js服务来运行rest-api,确保你本机已经安转node.js,如果没有安装，请安转一个<br />
2.命令行下安转node.js<br />
------npm install http-server -g<br />
3.在你本机上启动http-server运行rest-api<br />
------cd /opt/gopath/src/github.com/hyperledger/fabric/core/rest<br />
-------http-server -a 0.0.0.0 -p 5554 --cors<br />
4.浏览器中输入下面语句，确保能成功连接<br />
------http://localhost:5554/rest_api.json<br />
5.使用命令行下载 Swagger-UI包<br />
------git clone https://github.com/swagger-api/swagger-ui.git<br />
6.到 /swagger-ui/dist 下用浏览器打开index.html<br />
7.启动没有连接到leader or validator的peer节点<br />
----cd /opt/gopath/src/github.com/hyperledger/fabric<br />
-----build/bin/peer node start<br />
8.测试<br />
----cd /opt/gopath/src/github.com/hyperledger/fabric/core/rest<br />
----go test -v -run TestServerOpenchain_API_GetBlockCount</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&nbsp;</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">二、Node.Js应用程序<br />
构建并且安装 fabric core.<br />
&nbsp;&nbsp;&nbsp; cd /opt/gopath/src/github.com/hyperledger/fabric<br />
&nbsp;&nbsp;&nbsp; make peer<br />
在本地仅仅运行一个节点 (不是一个完整的网络) :<br />
&nbsp;&nbsp;&nbsp; build/bin/peer node start<br />
配置一个测试区块链数据结构通过vagrant来运行测试接下来重启peer进程.<br />
&nbsp;&nbsp;&nbsp; cd /opt/gopath/src/github.com/hyperledger/fabric/core/rest<br />
&nbsp;&nbsp;&nbsp; go test -v -run TestServerOpenchain_API_GetBlockCount<br />
在本地电脑上启动http-server来运行rest_api.json服务.<br />
&nbsp;&nbsp;&nbsp; npm install http-server -g<br />
&nbsp;&nbsp;&nbsp; cd /opt/gopath/src/github.com/hyperledger/fabric/core/rest<br />
&nbsp;&nbsp;&nbsp; http-server -a 0.0.0.0 -p 5554 --cors<br />
下载和解压 Sample_1.zip<br />
&nbsp;&nbsp;&nbsp; unzip Sample_1.zip -d Sample_1<br />
&nbsp;&nbsp;&nbsp; cd Sample_1<br />
如果没有默认的URL地址就在openchain.js文件中更新api_url变量以搭配合适的URL<br />
&nbsp;&nbsp;&nbsp; Update the api_url variable within openchain.js to the appropriate URL if it is not already the default<br />
&nbsp;&nbsp;&nbsp; var api_url = 'http://localhost:5554/rest_api.json';<br />
运行Node.js app<br />
&nbsp;&nbsp;&nbsp; node ./openchain.js</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-907-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-21 11:32</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-906-1.html</guid>
			<title>ubuntu下搭建HyperLedger fabric开发环境</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">一、安装docker</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">1、docker要求Linux内核版本不低于 3.10</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;检查Linux的内核版本,如果内核版本太低，升级内核</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;查看内核的版本命令uname -a</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">2、根据不同的Ubuntu版本安装docker</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;查看Ubuntu版本命令lsb_release -a</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">3、对于16.04的Ubuntu版本安装</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;sudo apt-get install docker-engine</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">4、启动</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;sudo systemctl enable docker</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;sudo systemctl start docker</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">二、从docker上拉取镜像</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">1、检验docker是否安装好</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;docker&nbsp;</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">2、从docker上拉镜像</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;docker pull hyperledger/fabric-peer:latest</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;docker pull hyperledger/fabric-membersrvc:latest</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">3、校验镜像是否拉取完成</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;docker images</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">三、安装docker-compose项目</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">1、安装pip工具</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;pip工具会依赖Python，而Ubuntu下默认已经安转好Python2.7</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;apt-get install python_pip</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">2、安转docker compose项目</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;sudo pip install -U docker-compose</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">3、校验docker compose是否安装好</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt; docker-compose -h</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">四、安装并配置nsenter工具</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">方法一、</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&nbsp;&gt;&gt;wget https://www.kernel.org/pub/linux/utils/util-linux/v2.29/util-linux-2.29.tar.xz; tar xJvf util-linux-2.29.tar.xz</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;cd util-linux-2.29</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt; ./configure --without-ncurses &amp;&amp; make nsenter</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;sudo cp nsenter /usr/local/bin</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">方法二、建议下载 .bashrc_docker，并将内容放到 .bashrc 中</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;wget -P ~ https://github.com/yeasy/docker_practice/raw/master/_local/.bashrc_docker;</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&gt;&gt;echo &quot;[ -f ~/.bashrc_docker ] &amp;&amp; . ~/.bashrc_docker&quot; &gt;&gt; ~/.bashrc; source ~/.bashrc</span><br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<br style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">五、启动节点</span></p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">1、在root的Home目录下创建<a href="http://lib.csdn.net/base/4" class="replace_word" title="undefined" target="_blank" style="text-decoration: none; color: rgb(223, 52, 52); font-weight: bold;">Docker</a>-compose.yml并写入一下内容</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&nbsp;</p>
<pre style="white-space: pre-wrap; word-wrap: break-word; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px;"><code class="hljs haml" style="display: block; padding: 0.5em; color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">membersrvc:   image: hyperledger/fabric-membersrvc   ports:     -<span class="ruby"> <span class="hljs-string" style="color: rgb(0, 136, 0);">&quot;7054:7054&quot;</span> </span>  command: membersrvc vp0:   image: hyperledger/fabric-peer   ports:     -<span class="ruby"> <span class="hljs-string" style="color: rgb(0, 136, 0);">&quot;7050:7050&quot;</span> </span>    -<span class="ruby"> <span class="hljs-string" style="color: rgb(0, 136, 0);">&quot;7051:7051&quot;</span> </span>    -<span class="ruby"> <span class="hljs-string" style="color: rgb(0, 136, 0);">&quot;7053:7053&quot;</span> </span>  environment:     -<span class="ruby"> <span class="hljs-constant">CORE_PEER_ADDRESSAUTODETECT</span>=<span class="hljs-keyword" style="color: rgb(0, 0, 136);">true</span> </span>    -<span class="ruby"> <span class="hljs-constant">CORE_VM_ENDPOINT</span>=<span class="hljs-symbol" style="color: rgb(0, 102, 102);">unix:</span>/<span class="hljs-regexp" style="color: rgb(0, 136, 0);">//var</span><span class="hljs-regexp" style="color: rgb(0, 136, 0);">/run/docker</span>.sock </span>    -<span class="ruby"> <span class="hljs-constant">CORE_LOGGING_LEVEL</span>=<span class="hljs-constant">DEBUG</span> </span>    -<span class="ruby"> <span class="hljs-constant">CORE_PEER_ID</span>=vp<span class="hljs-number" style="color: rgb(0, 102, 102);">0</span> </span>    -<span class="ruby"> <span class="hljs-constant">CORE_PEER_PKI_ECA_PADDR</span>=<span class="hljs-symbol" style="color: rgb(0, 102, 102);">membersrvc:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">7054</span> </span>    -<span class="ruby"> <span class="hljs-constant">CORE_PEER_PKI_TCA_PADDR</span>=<span class="hljs-symbol" style="color: rgb(0, 102, 102);">membersrvc:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">7054</span> </span>    -<span class="ruby"> <span class="hljs-constant">CORE_PEER_PKI_TLSCA_PADDR</span>=<span class="hljs-symbol" style="color: rgb(0, 102, 102);">membersrvc:</span><span class="hljs-number" style="color: rgb(0, 102, 102);">7054</span> </span>    -<span class="ruby"> <span class="hljs-constant">CORE_SECURITY_ENABLED</span>=<span class="hljs-keyword" style="color: rgb(0, 0, 136);">true</span> </span>    -<span class="ruby"> <span class="hljs-constant">CORE_SECURITY_ENROLLID</span>=test_vp<span class="hljs-number" style="color: rgb(0, 102, 102);">0</span> </span>    -<span class="ruby"> <span class="hljs-constant">CORE_SECURITY_ENROLLSECRET</span>=<span class="hljs-constant">MwYpmSRjupbT</span> </span>  links:     -<span class="ruby"> membersrvc </span>  command: sh -c &quot;sleep 5; peer node start --peer-chaincodedev&quot;  </code></pre>
<p><span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">2、通过docker-compose up运行已近配置好的节点</span></p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">&nbsp;</p>
<p style="margin-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">六、进入容器<br />
1、docker -ps 找到要进入的容器的CONTAINER ID<br />
2、用docker-pid指令获取需要进入容器的PID<br />
&gt;&gt;echo PID=(docker-pid&nbsp; b4378c920828)<br />
3、借助PID进入容器<br />
&gt;&gt;sudo nsenter --target 10981 --mount --uts --ipc --net --pid<br />
<br />
七、测试环境是否搭建好<br />
1、选择源码中的一个例子chaincode机型编译<br />
&gt;&gt;cd$GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02<br />
&gt;&gt;go build<br />
2、注册和运行chaincode<br />
&gt;&gt;CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:7051 ./chaincode_example02<br />
<br />
3、另起一个终端，进入容器的方式和&ldquo;六&rdquo;一样，以WebAppAdmin的形式登录到节点上<br />
&gt;&gt;peer network login WebAppAdmin -p DJY27pEnl16d<br />
4、执行下面的代码，在另外一个终端里面会看到执行结果<br />
安全模式<br />
部署交易<br />
&gt;&gt;CORE_SECURITY_ENABLED=true CORE_SECURITY_PRIVACY=true peer chaincode deploy -u WebAppAdmin -n mycc -c '{&quot;Function&quot;:&quot;init&quot;, &quot;Args&quot;: [&quot;a&quot;,&quot;100&quot;, &quot;b&quot;, &quot;200&quot;]}'<br />
调用交易<br />
&gt;&gt;CORE_SECURITY_ENABLED=true CORE_SECURITY_PRIVACY=true peer chaincode invoke -u WebAppAdmin -l golang -n mycc -c '{&quot;Function&quot;: &quot;invoke&quot;, &quot;Args&quot;: [&quot;a&quot;, &quot;b&quot;, &quot;10&quot;]}'<br />
查询交易<br />
&gt;&gt;CORE_SECURITY_ENABLED=true CORE_SECURITY_PRIVACY=true peer chaincode query -u WebAppAdmin -l golang -n mycc -c '{&quot;Function&quot;: &quot;query&quot;, &quot;Args&quot;: [&quot;b&quot;]}'</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-906-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-21 11:31</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-881-1.html</guid>
			<title>dragonchain</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;[root@localhost dragonchain-master]# python blockchain/transaction_svc.py transaction_svc.py --private-key sk.pem --public-key pk.pem</p>
<div>Traceback (most recent call last):</div>
<div>&nbsp; File &quot;blockchain/transaction_svc.py&quot;, line 39, in &lt;module&gt;</div>
<div>&nbsp; &nbsp; import tornado</div>
<div>ImportError: No module named tornado</div>
<div>&nbsp;</div>
<div>pip install tornado</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>---</div>
<div>http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html</div>
<div>https://yum.postgresql.org/repopackages.php#pg94</div>
<div>https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm</div>
<div>&nbsp;</div>
<div>&nbsp;1060 &nbsp;yum install postgresql96-server</div>
<div>&nbsp;1061 &nbsp;yum install postgresql96-contrib</div>
<div>&nbsp;1062 &nbsp;psql</div>
<div>&nbsp;1063 &nbsp;/etc/rc.d/init.d/postgresql-9.6</div>
<div>&nbsp;1064 &nbsp;/etc/rc.d/init.d/postgresql-9.6 start</div>
<div>&nbsp;1065 &nbsp;/etc/rc.d/init.d/postgresql-9.6 initdb</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>---</div>
<div>openssl</div>
<div>http://blog.csdn.net/as3luyuan123/article/details/14406429</div>
<div>http://www.docin.com/p-670347159.html</div>
<div>openssl</div>
<div>ecparam -list_curves</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>---</div>
<div>1.Linux环境下 &nbsp;</div>
<div>#su &nbsp;postgres &nbsp;&nbsp;</div>
<div>-bash-3.2$psql -U postgres &nbsp;&nbsp;</div>
<div>postgres=#alter user postgres with password 'new password'; &nbsp;</div>
<div>postgres=#\q&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>SELECT rolname FROM pg_roles;</div>
<div>&nbsp;</div>
<div>创建用户 &nbsp;</div>
<div>grant all on all tables in schema schemaName to user; 给用户某个schema的所有权限 &nbsp;</div>
<div>----</div>
<div>cd &lt;Dragonchain Home&gt;/sql</div>
<div>createuser blocky</div>
<div>createdb -O blocky blockchain</div>
<div>psql -U blocky -d blockchain -a -f depl.sql</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>http://blog.csdn.net/suirosu/article/details/39718013</div>
<div>http://www.cyberciti.biz/faq/psql-fatal-ident-authentication-failed-for-user/</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-881-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-16 11:01</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-876-1.html</guid>
			<title>Hyperledger智能合约Hello World示例程序</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;</p>
<h3 id="简介" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">简介</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">Hyperledger是Linux 基金会主导的一个开源的区块链(BlockChain)项目. 本文介绍了一个简单的Hyperledger智能合约的开发过程.</p>
<h3 id="开发环境" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">开发环境</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">本文使用Docker作为Hyperledger智能合约的本地开发环境.</p>
<h3 id="第一步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第一步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">从Docker官网<code style="margin: 1px 5px; padding: 0px 5px !important; line-height: 1.8; vertical-align: middle; display: inline-block; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-color: rgb(245, 245, 245) !important;">http://www.docker.com/</code>下载其安装包，并安装Docker.</p>
<h3 id="第二步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第二步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">启动Docker QuickStarter Terminal并运行如下命令在Docker中安装Hyperledger Fabric.</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs groovy" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">docker pull hyperledger/fabric-<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">peer:</span>latest docker pull hyperledger/fabric-<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">membersrvc:</span>latest</code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;"><img src="http://images2015.cnblogs.com/blog/1026414/201610/1026414-20161006202016270-1761376988.png" style="margin: 0px; padding: 0px; border: 0px; max-width: 900px;" alt="" /></p>
<h3 id="第三步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第三步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">在工作目录下创建如下的<code style="margin: 1px 5px; padding: 0px 5px !important; line-height: 1.8; vertical-align: middle; display: inline-block; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-color: rgb(245, 245, 245) !important;">docker-compose.yml</code></p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs dts" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">membersrvc:</span> <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">  image:</span> hyperledger/fabric-membersrvc <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">  ports:</span>     - <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;7054:7054&quot;</span> <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">  command:</span> membersrvc <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">vp0:</span> <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">  image:</span> hyperledger/fabric-peer <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">  ports:</span>     - <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;7050:7050&quot;</span>     - <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;7051:7051&quot;</span>     - <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;7053:7053&quot;</span> <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">  environment:</span>     - CORE_PEER_ADDRESSAUTODETECT=true     - CORE_VM_ENDPOINT=unix:<span class="hljs-comment" style="margin: 0px; padding: 0px; color: green;">///var/run/docker.sock</span>     - CORE_LOGGING_LEVEL=DEBUG     - CORE_PEER_ID=vp0     - CORE_PEER_PKI_ECA_PADDR=membersrvc:<span class="hljs-number" style="margin: 0px; padding: 0px;">7054</span>     - CORE_PEER_PKI_TCA_PADDR=membersrvc:<span class="hljs-number" style="margin: 0px; padding: 0px;">7054</span>     - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:<span class="hljs-number" style="margin: 0px; padding: 0px;">7054</span>     - CORE_SECURITY_ENABLED=true     - CORE_SECURITY_ENROLLID=test_vp0     - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">  links:</span>     - membersrvc <span class="hljs-symbol" style="margin: 0px; padding: 0px; color: rgb(0, 176, 232);">  command:</span> sh -c <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;sleep 5; peer node start --peer-chaincodedev&quot;</span></code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">然后在Docker QuickStarter Terminal中运行以下命令以启动Hyperledger Fabric</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">docker-compose up</code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;"><img src="http://images2015.cnblogs.com/blog/1026414/201610/1026414-20161006200859457-1786750997.png" style="margin: 0px; padding: 0px; border: 0px; max-width: 900px;" alt="" /></p>
<h3 id="第四步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第四步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">安装并运行SSH客户端，例如putty或mRemoteNG, 使用以下信息连接Docker</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs css" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-selector-tag" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">host</span> : 192<span class="hljs-selector-class" style="margin: 0px; padding: 0px;">.168</span><span class="hljs-selector-class" style="margin: 0px; padding: 0px;">.99</span><span class="hljs-selector-class" style="margin: 0px; padding: 0px;">.100</span> <span class="hljs-selector-tag" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">user</span> <span class="hljs-selector-tag" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">name</span> : <span class="hljs-selector-tag" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">docker</span> <span class="hljs-selector-tag" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">password</span> : <span class="hljs-selector-tag" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">tcuser</span></code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;"><img src="http://images2015.cnblogs.com/blog/1026414/201610/1026414-20161006200920457-1537895224.png" style="margin: 0px; padding: 0px; border: 0px; max-width: 900px;" alt="" /></p>
<h3 id="第五步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第五步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">运行如下命令以确认Hyperledger Fabric的进程</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs nginx" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-attribute" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">docker</span> ps</code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">运行如下命令以进入Hyperledger Fabric环境</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs python" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">docker <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">exec</span> -it hyperledger_vp0_1 bash</code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;"><img src="http://images2015.cnblogs.com/blog/1026414/201610/1026414-20161006200949379-295643143.png" style="margin: 0px; padding: 0px; border: 0px; max-width: 900px;" alt="" /></p>
<h3 id="第六步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第六步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">运行如下命令从git下载Hyperledger Fabric源代码</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs bash" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">mkdir -p <span class="hljs-variable" style="margin: 0px; padding: 0px; color: green;">$GOPATH</span>/src/github.com/hyperledger <span class="hljs-built_in" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">cd</span> <span class="hljs-variable" style="margin: 0px; padding: 0px; color: green;">$GOPATH</span>/src/github.com/hyperledger git <span class="hljs-built_in" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">clone</span> http://gerrit.hyperledger.org/r/fabric</code></pre>
<h3 id="第七步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第七步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">运行如下命令创建HelloWorld目录</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs groovy" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">mkdir -p $GOPATH<span class="hljs-regexp" style="margin: 0px; padding: 0px;">/src/</span>github.com<span class="hljs-regexp" style="margin: 0px; padding: 0px;">/HelloWorld/</span> cd $GOPATH<span class="hljs-regexp" style="margin: 0px; padding: 0px;">/src/</span>github.com<span class="hljs-regexp" style="margin: 0px; padding: 0px;">/HelloWorld/</span></code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">创建如下HelloWorld.go文件</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs go" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">package</span> main  <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">import</span> (     <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;errors&quot;</span>     <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;fmt&quot;</span>     <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;strconv&quot;</span>      <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;github.com/hyperledger/fabric/core/chaincode/shim&quot;</span> )   <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">type</span> HelloWorldChaincode <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">struct</span> { }  <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">func</span> (t *HelloWorldChaincode) Init(stub shim.ChaincodeStubInterface, function <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">string</span>, args []<span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">string</span>) ([]<span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">byte</span>, error) {     fmt.Printf(<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;HelloWorld - Init called with function %s!\n&quot;</span>, function)      <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">return</span> <span class="hljs-literal" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">nil</span>, <span class="hljs-literal" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">nil</span> }  <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">func</span> (t *HelloWorldChaincode) Invoke(stub shim.ChaincodeStubInterface, function <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">string</span>, args []<span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">string</span>) ([]<span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">byte</span>, error) {     fmt.Printf(<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;HelloWorld - Invoke called with function %s!\n&quot;</span>, function)      <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">return</span> <span class="hljs-literal" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">nil</span>, <span class="hljs-literal" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">nil</span>     }  <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">func</span> (t *HelloWorldChaincode) Query(stub shim.ChaincodeStubInterface, function <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">string</span>, args []<span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">string</span>) ([]<span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">byte</span>, error) {     fmt.Printf(<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;HelloWorld - Query called with function %s!\n&quot;</span>, function)      message := <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;Hello World&quot;</span>     <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">return</span> []<span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">byte</span>(message), <span class="hljs-literal" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">nil</span>; }  <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">func</span> main() {     err := shim.Start(<span class="hljs-built_in" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">new</span>(HelloWorldChaincode))     <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">if</span> err != <span class="hljs-literal" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">nil</span> {         fmt.Printf(<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;Error starting Hello World chaincode: %s&quot;</span>, err)     } }</code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">使用如下命令编译代码</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs go" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">go</span> build ./ </code></pre>
<h3 id="第八步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第八步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">使用如下命令运行HelloWorld</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs cpp" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">export</span> CORE_CHAINCODE_ID_NAME=mycc <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">export</span> CORE_PEER_ADDRESS=<span class="hljs-number" style="margin: 0px; padding: 0px;">0.0</span><span class="hljs-number" style="margin: 0px; padding: 0px;">.0</span><span class="hljs-number" style="margin: 0px; padding: 0px;">.0</span>:<span class="hljs-number" style="margin: 0px; padding: 0px;">7051</span> ./HelloWorld &amp;</code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;"><img src="http://images2015.cnblogs.com/blog/1026414/201610/1026414-20161006201025879-1392860904.png" style="margin: 0px; padding: 0px; border: 0px; max-width: 900px;" alt="" /></p>
<h3 id="第九步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第九步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">向Hyperledger服务接口<code style="margin: 1px 5px; padding: 0px 5px !important; line-height: 1.8; vertical-align: middle; display: inline-block; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-color: rgb(245, 245, 245) !important;">http://192.168.99.100:7050/registrar</code>&nbsp;发送如下REST请求，使用内置的jim用户登录系统</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs json" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">{     &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">enrollId</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;jim&quot;</span>,     &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">enrollSecret</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;6avZQLwcUe9b&quot;</span> }</code></pre>
<h3 id="第十步" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">第十步</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">向Hyperledger服务接口<code style="margin: 1px 5px; padding: 0px 5px !important; line-height: 1.8; vertical-align: middle; display: inline-block; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-color: rgb(245, 245, 245) !important;">http://192.168.99.100:7050/chaincode</code>&nbsp;发送如下初始化HelloWorld的REST请求</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs json" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">{    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">jsonrpc</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;2.0&quot;</span>,    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">method</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;deploy&quot;</span>,    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">params</span>&quot;: {     &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">type</span>&quot;: <span class="hljs-number" style="margin: 0px; padding: 0px;">1</span>,     &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">chaincodeID</span>&quot;:{         &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">name</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;mycc&quot;</span>     },     &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">ctorMsg</span>&quot;: {          &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">function</span>&quot;:<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;init&quot;</span>,          &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">args</span>&quot;:[]      },     &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">secureContext</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;jim&quot;</span>   },    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">id</span>&quot;: <span class="hljs-number" style="margin: 0px; padding: 0px;">1</span>  }</code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">调用HelloWorld的REST请求</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs json" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">{    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">jsonrpc</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;2.0&quot;</span>,    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">method</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;invoke&quot;</span>,    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">params</span>&quot;: {        &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">type</span>&quot;: <span class="hljs-number" style="margin: 0px; padding: 0px;">1</span>,        &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">chaincodeID</span>&quot;:{            &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">name</span>&quot;:<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;mycc&quot;</span>        },        &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">ctorMsg</span>&quot;: {           &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">function</span>&quot;:<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;invoke&quot;</span>,           &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">args</span>&quot;:[]        },        &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">secureContext</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;jim&quot;</span>    },    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">id</span>&quot;: <span class="hljs-number" style="margin: 0px; padding: 0px;">3</span>  }  </code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">以及查询HelloWorld的REST请求</p>
<pre style="margin-top: 10px; margin-bottom: 10px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(17, 17, 17); font-size: 13px; line-height: 23.4px;"><code class="hljs json" style="margin: auto; vertical-align: middle; display: block; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">{    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">jsonrpc</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;2.0&quot;</span>,    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">method</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;query&quot;</span>,    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">params</span>&quot;: {        &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">type</span>&quot;: <span class="hljs-number" style="margin: 0px; padding: 0px;">1</span>,        &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">chaincodeID</span>&quot;:{            &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">name</span>&quot;:<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;mycc&quot;</span>        },        &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">ctorMsg</span>&quot;: {           &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">function</span>&quot;:<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;query&quot;</span>,           &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">args</span>&quot;:[]        },        &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">secureContext</span>&quot;: <span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21);">&quot;jim&quot;</span>    },    &quot;<span class="hljs-attr" style="margin: 0px; padding: 0px; color: red;">id</span>&quot;: <span class="hljs-number" style="margin: 0px; padding: 0px;">5</span>  }</code></pre>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;"><img src="http://images2015.cnblogs.com/blog/1026414/201610/1026414-20161006201058692-1104834228.png" style="margin: 0px; padding: 0px; border: 0px; max-width: 900px;" alt="" /></p>
<h3 id="总结" style="margin: 10px 0px; padding: 0px; font-size: 16px; line-height: 1.5; font-family: Verdana, Arial, Helvetica, sans-serif;">总结</h3>
<p style="margin: 10px auto; color: rgb(17, 17, 17); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 23.4px;">本文介绍了一个简单的Hyperledger智能合约在本地Docker环境下的开发过程.</p>
<p style="margin: 10px auto;"><font color="#111111" face="Verdana, Arial, Helvetica, sans-serif"><span style="font-size: 13px; line-height: 23.4px;">http://www.cnblogs.com/huyouhengbc/p/5934683.html#3545114</span></font></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-876-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 22:52</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-875-1.html</guid>
			<title>以太坊智能合约编程之菜鸟教程</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<em style="color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px; box-sizing: inherit;">译注：<a href="http://consensys.github.io/developers/articles/101-noob-intro/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">原文</a>首发于ConsenSys开发者博客，原作者为Eva以及ConsenSys的开发团队。如果您想要获取更多及时信息，可以访问<a href="https://consensys.net/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">ConsenSys</a>首页点击左下角Newsletter订阅邮件。本文的翻译获得了ConsenSys创始人Lubin先生的授权。</em></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">有些人说以太坊太难对付，于是我们(译注：指<a href="http://consensys.net/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Consensys</a>, 下同)写了这篇文章来帮助大家学习如何利用以太坊编写智能合约和应用。这里所用到的工具，钱包，应用程序以及整个生态系统仍处于开发状态，它们将来会更好用！</p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;"><a href="http://ethfans.org/posts/101-noob-intro#%E7%AC%AC%E4%B8%80%E9%83%A8%E5%88%86.%20%E6%A6%82%E8%BF%B0" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">第一部分</a>概述，讨论了关键概念，几大以太坊客户端以及写智能合约用到的编程语言。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;"><a href="http://ethfans.org/posts/101-noob-intro#%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.%20DApp%E6%A1%86%E6%9E%B6,%20%E5%B7%A5%E5%85%B7%E4%BB%A5%E5%8F%8A%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">第二部分</a>讨论了总体的工作流程，以及目前流行的一些DApp框架和工具。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;"><a href="http://ethfans.org/posts/101-noob-intro#%E7%AC%AC%E4%B8%89%E9%83%A8%E5%88%86.%20%E7%BC%96%E7%A8%8B" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">第三部分</a>主要关于编程，我们将学习如何使用Truffle来为智能合约编写测试和构建DApp。</li>
</ul>
<h2 id="第一部分. 概述" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">第一部分. 概述</h2>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">如果你对诸如比特币以及其工作原理等密码学货币的概念完全陌生，我们建议你先看看Andreas Antonopoulos所著的<a href="https://github.com/aantonop/bitcoinbook" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Bitcoin Book</a>的头几章，然后读一下<a href="https://github.com/ethereum/wiki/wiki/White-Paper" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">以太坊白皮书</a>。(译注：以太坊白皮书中文版请看&nbsp;<a href="http://ethfans.org/posts/ethereum-whitepaper" rel="nofollow" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">http://ethfans.org/posts/ethereum-whitepaper</a>)</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">如果你觉得白皮书中的章节太晦涩，也可以直接动手来熟悉以太坊。在以太坊上做开发并不要求你理解所有那些&ldquo;密码经济计算机科学&rdquo;(crypto economic computer science)，而白皮书的大部分是关于以太坊想对于比特币架构上的改进。</p>
<h3 id="新手教程" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">新手教程</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><a href="http://ethereum.org/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">ethereum.org</a>提供了官方的新手入门教程，以及一个代币合约和众筹合约的教程。合约语言Solidity也有<a href="https://ethereum.github.io/solidity/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">官方文档</a>。学习智能合约的另一份不错的资料（也是我的入门资料）是<a href="https://dappsforbeginners.wordpress.com/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">dappsForBeginners</a>，不过现在可能有些过时了。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">这篇文章的目的是成为上述资料的补充，同时介绍一些基本的开发者工具，使入门以太坊，智能合约以及构建DApps(decentralized apps, 分布式应用)更加容易。我会试图按照我自己(依然是新手)的理解来解释工作流程中的每一步是在做什么，我也得到了ConsenSys酷酷的开发者们的许多帮助。</p>
<h3 id="基本概念" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">基本概念</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">了解这些名词是一个不错的开始：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">公钥加密系统。</strong>&nbsp;Alice有一把公钥和一把私钥。她可以用她的私钥创建数字签名，而Bob可以用她的公钥来验证这个签名确实是用Alice的私钥创建的，也就是说，确实是Alice的签名。当你创建一个以太坊或者比特币钱包的时候，那长长的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">0xdf...5f</code>地址实质上是个公钥，对应的私钥保存某处。类似于Coinbase的在线钱包可以帮你保管私钥，你也可以自己保管。如果你弄丢了存有资金的钱包的私钥，你就等于永远失去了那笔资金，因此你最好对私钥做好备份。过来人表示：通过踩坑学习到这一点是非常痛苦的...</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">点对点网络。</strong>&nbsp;就像BitTorrent, 以太坊分布式网络中的所有节点都地位平等，没有中心服务器。(未来会有半中心化的混合型服务出现为用户和开发者提供方便，这我们后面会讲到。)</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">区块链。</strong>&nbsp;区块链就像是一个全球唯一的帐簿，或者说是数据库，记录了网络中所有交易历史。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">以太坊虚拟机(EVM)。</strong>&nbsp;它让你能在以太坊上写出更强大的程序（比特币上也可以写脚本程序）。它有时也用来指以太坊区块链，负责执行智能合约以及一切。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">节点。</strong>&nbsp;你可以运行节点，通过它读写以太坊区块链，也即使用以太坊虚拟机。完全节点需要下载整个区块链。轻节点仍在开发中。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">矿工。</strong>&nbsp;挖矿，也就是处理区块链上的区块的节点。这个网页可以看到当前活跃的一部分以太坊矿工：<a href="http://stats.ethdev.com/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">stats.ethdev.com</a>。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">工作量证明。</strong>&nbsp;矿工们总是在竞争解决一些数学问题。第一个解出答案的(算出下一个区块)将获得以太币作为奖励。然后所有节点都更新自己的区块链。所有想要算出下一个区块的矿工都有与其他节点保持同步，并且维护同一个区块链的动力，因此整个网络总是能达成共识。(注意：以太坊正计划转向没有矿工的权益证明系统(POS)，不过那不在本文讨论范围之内。)</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">以太币。</strong>&nbsp;缩写ETH。一种你可以购买和使用的真正的数字货币。这里是可以交易以太币的其中一家交易所的<a href="https://poloniex.com/exchange#usdt_eth" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">走势图</a>。在写这篇文章的时候，1个以太币价值65美分。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Gas. (汽油)</strong>&nbsp;在以太坊上执行程序以及保存数据都要消耗一定量的以太币，Gas是以太币转换而成。这个机制用来保证效率。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">DApp.</strong>&nbsp;以太坊社区把基于智能合约的应用称为去中心化的应用程序(Decentralized App)。DApp的目标是(或者应该是)让你的智能合约有一个友好的界面，外加一些额外的东西，例如IPFS（可以存储和读取数据的去中心化网络，不是出自以太坊团队但有类似的精神)。DApp可以跑在一台能与以太坊节点交互的中心化服务器上，也可以跑在任意一个以太坊平等节点上。(花一分钟思考一下：与一般的网站不同，DApp不能跑在普通的服务器上。他们需要提交交易到<strong style="box-sizing: inherit;">区块链</strong>并且从<strong style="box-sizing: inherit;">区块链</strong>而不是中心化数据库读取<strong style="box-sizing: inherit;">重要</strong>数据。相对于典型的用户登录系统，用户有可能被表示成一个钱包地址而其它用户数据保存在本地。许多事情都会与目前的web应用有不同架构。)</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">如果想看看从另一个新手视角怎么理解这些概念，请读<a href="https://medium.com/@user1/time-sure-does-fly-ed4518792679" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Just Enough Bitcoin for Ethereum</a>。</p>
<h3 id="以太坊客户端，智能合约语言" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">以太坊客户端，智能合约语言</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">编写和部署智能合约并不要求你运行一个以太坊节点。下面有列出<a href="http://ethfans.org/posts/101-noob-intro#browser_ides" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">基于浏览器的IDE和API</a>。但如果是为了学习的话，还是应该运行一个以太坊节点，以便理解其中的基本组件，何况运行节点也不难。</p>
<h4 id="运行以太坊节点可用的客户端" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 16px; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">运行以太坊节点可用的客户端</h4>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">以太坊有许多不同语言的客户端实现（即多种与以太坊网络交互的方法），包括C++, Go, Python, Java, Haskell等等。为什么需要这么多实现？不同的实现能满足不同的需求（例如Haskell实现的目标是可以被数学验证），能使以太坊更加安全，能丰富整个生态系统。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">在写作本文时，我使用的是Go语言实现的客户端geth (<a href="http://ethereum.github.io/go-ethereum/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">go-ethereum</a>)，其他时候还会使用一个叫testrpc的工具, 它使用了Python客户端<a href="https://github.com/ethereum/pyethereum" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">pyethereum</a>。后面的例子会用到这些工具。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">注: 我曾经使用过C++的客户端，现在仍然在用其中的ethminer组件和geth配合挖矿，因此这些不同的组件是可以一起工作的。<br style="box-sizing: inherit;" />
关于挖矿：挖矿很有趣，有点像精心照料你的室内盆栽，同时又是一种了解整个系统的方法。虽然以太币现在的价格可能连电费都补不齐，但以后谁知道呢。人们正在创造许多酷酷的DApp, 可能会让以太坊越来越流行。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">交互式控制台。</strong>&nbsp;客户端运行起来后，你就可以同步区块链，建立钱包，收发以太币了。使用geth的一种方式是通过<a href="https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Javascript控制台</a>（JavaScript console, 类似你在chrome浏览器里面按F12出来的那个，只不过是跑在终端里）。此外还可以使用类似cURL的命令通过<a href="https://github.com/ethereum/wiki/wiki/JSON-RPC" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">JSON RPC</a>来与客户端交互。本文的目标是带大家过一边DApp开发的流程，因此这块就不多说了。但是我们应该记住这些命令行工具是调试，配置节点，以及使用钱包的利器。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">在测试网络运行节点。</strong>&nbsp;如果你在正式网络运行geth客户端，下载整个区块链与网络同步会需要相当时间。（你可以通过比较节点日志中打印的最后一个块号和<a href="http://stats.ethdev.com/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">stats.ethdev.com</a>上列出的最新块来确定是否已经同步。) 另一个问题是在正式网络上跑智能合约需要实实在在的以太币。在测试网络上运行节点的话就没有这个问题。此时也不需要同步整个区块链，创建一个自己的私有链就勾了，对于开发来说更省时间。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">testrpc.</strong>&nbsp;用geth可以创建一个测试网络，另一种更快的创建测试网络的方法是使用testrpc. Testrpc可以在启动时帮你创建一堆存有资金的测试账户。它的运行速度也更快因此更适合开发和测试。你可以从testrpc起步，然后随着合约慢慢成型，转移到geth创建的测试网络上 - 启动方法很简单，只需要指定一个networkid：<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">geth --networkid &quot;12345&quot;</code>。这里是<a href="https://github.com/ConsenSys/eth-testrpc" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">testrpc的代码仓库</a>，下文我们还会再讲到它。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">接下来我们来谈谈可用的编程语言，之后就可以开始真正的编程了。</p>
<h4 id="写智能合约用的编程语言" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 16px; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">写智能合约用的编程语言</h4>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">用Solidity就好。</strong>&nbsp;要写智能合约有好几种语言可选：有点类似Javascript的Solidity, 文件扩展名是<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">.sol</code>. 和Python接近的Serpent, 文件名以<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">.se</code>结尾。还有类似Lisp的LLL。Serpent曾经流行过一段时间，但现在最流行而且最稳定的要算是Solidity了，因此用Solidity就好。听说你喜欢Python? 用Solidity。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">solc编译器。</strong>&nbsp;用Solidity写好智能合约之后，需要用solc来编译。它是一个来自C++客户端实现的组件（又一次，不同的实现产生互补），<a href="https://github.com/ethereum/webthree-umbrella/wiki" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">这里</a>是安装方法。如果你不想安装solc也可以直接使用基于浏览器的编译器，例如<a href="https://chriseth.github.io/browser-solidity/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Solidity real-time compiler</a>或者<a href="http://cosmo.to/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Cosmo</a>。后文有关编程的部分会假设你安装了solc。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">注意：以太坊正处于积极的开发中，有时候新的版本之间会有不同步。确认你使用的是最新的dev版本，或者稳定版本。如果遇到问题可以去以太坊项目对应的Gitter聊天室或者<a href="http://forums.ethereum.org/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">forums.ethereum.org</a>上问问其他人在用什么版本。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">web3.js API.</strong>&nbsp;当Solidity合约编译好并且发送到网络上之后，你可以使用以太坊的<a href="https://github.com/ethereum/wiki/wiki/JavaScript-API" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">web3.js JavaScript API</a>来调用它，构建能与之交互的web应用。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">以上就是在以太坊上编写智能合约和构建与之交互的DApp所需的基本工具。</p>
<h2 id="第二部分. DApp框架，工具以及工作流程" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">第二部分. DApp框架，工具以及工作流程</h2>
<h3 id="DApp开发框架" style="box-sizing: inherit; margin: 0px 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">DApp开发框架</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">虽然有上文提到的工具就可以进行开发了，但是使用社区大神们创造的框架会让开发更容易。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Truffle and Embark.</strong>&nbsp;是<a href="https://github.com/ConsenSys/truffle" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Truffle</a>把我领进了门。在Truffle出现之前的那个夏天，我目睹了一帮有天分的学生是如何不眠不休的参加一个hackathon（编程马拉松）活动的，虽然<a href="https://www.youtube.com/watch?v=TJBHTT88I8k" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">结果相当不错</a>，但我还是吓到了。然后Truffle出现了，帮你处理掉大量无关紧要的小事情，让你可以迅速进入写代码-编译-部署-测试-打包DApp这个流程。另外一个相似的DApp构建与测试框架是<a href="https://iurimatias.github.io/embark-framework" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Embark</a>。我只用过Truffle, 但是两个阵营都拥有不少DApp大神。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Meteor.</strong>&nbsp;许多DApp开发者使用的另一套开发栈由web3.js和<a href="https://www.meteor.com/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Meteor</a>组成，Meteor是一套通用webapp开发框架（<a href="https://github.com/ethereum/meteor-dapp-wallet" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">ethereum-meteor-wallet</a>项目提供了一个很棒的入门实例，而<a href="https://github.com/SilentCicero" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">SilentCiero</a>正在构建大量Meteor与web3.js和DApp集成的模板）。我下载并运行过一些不错的DApp是以这种方式构造的。在11月9日至13日的<a href="http://consensys.github.io/developers/articles/101-noob-intro/devcon.ethereum.org" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">以太坊开发者大会&ETH;&Xi;VCON1</a>上将有一些有趣的讨论，是关于使用这些工具构建DApp以及相关最佳实践的（会议将会在<a href="https://www.youtube.com/channel/UC6rYoXJ_3BbPyWx_GQDDRRQ" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">YouTube</a>上直播）。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">APIs.</strong>&nbsp;<a href="http://blockapps.net/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">BlockApps.net</a>打算提供一套RESTful API给DApp使用以免去开发者运行本地节点的麻烦，这个中心化服务是基于以太坊Haskell实现的。这与DApp的去中心化模型背道而驰，但是在本地无法运行以太坊节点的场合非常有用，比如在你希望只有浏览器或者使用移动设备的用户也能使用你的DApp的时候。BlockApps提供了一个命令行工具<a href="https://github.com/blockapps/bloc" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">bloc</a>，注册一个开发者帐号之后就可以使用。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">许多人担心需要运行以太坊节点才能使用DApp的话会把用户吓跑，其实包括BlockApps在内的许多工具都能解决这个问题。<a href="https://metamask.io/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Metamask</a>允许你在浏览器里面使用以太坊的功能而无需节点，以太坊官方提供的AlethZero或者AlethOne是正在开发中有易用界面的客户端，ConsenSys正在打造一个轻钱包<a href="https://github.com/ConsenSys/eth-lightwallet" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">LightWallet</a>，这些工具都会让DApp的使用变得更容易。<a href="https://github.com/ethereum/wiki/wiki/White-Paper#scalability" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">轻客户端</a>和水平分片(sharding)也在计划和开发之中。这是一个能进化出混合架构的P2P生态系统。</p>
<h3 id="智能合约集成开发环境 (IDE)" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">智能合约集成开发环境 (IDE)</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">IDE.</strong>&nbsp;以太坊官方出品了用来编写智能合约的<a href="https://github.com/ethereum/wiki/wiki/Mix:-The-DApp-IDE" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Mix IDE</a>，我还没用过但会尽快一试。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">基于浏览器的IDE.</strong>&nbsp;<a href="https://chriseth.github.io/browser-solidity" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Solidity real-time compiler</a>和<a href="http://cosmo.to/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Cosmo</a>都可以让你快速开始在浏览器中编写智能合约。你甚至可以让这些工具使用你的本地节点，只要让本地节点开一个端口（注意安全！这些工具站点必须可信，而且千万不要把你的全部身家放在这样一个本地节点里面！<a href="http://cosmo.to/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Cosmo UI</a>上有如何使用geth做到这一点的指引）。在你的智能合约调试通过之后，可以用开发框架来给它添加用户界面和打包成DApp，这正是Truffle的工作，后面的编程章节会有详细讲解。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><a href="http://frontier.ether.camp/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Ether.Camp</a>正在开发另一个强大的企业级浏览器IDE。他们的IDE将支持沙盒测试网络，自动生成用于测试的用户界面（取代后文将展示的手动编写测试），以及一个测试交易浏览器<a href="http://test.ether.camp/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">test.ether.camp</a>。当你的合约准备正式上线之前，使用他们的测试网络会是确保你的智能合约在一个接近真实的环境工作正常的好方法。他们也为正式网络提供了一个交易浏览器<a href="http://frontier.ether.camp/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">frontier.ether.camp</a>，上面可以看到每一笔交易的细节。在本文写作时Ether.Camp的IDE还只能通过邀请注册，预计很快会正式发布。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">合约和Dapp示例。</strong>&nbsp;在Github上搜索DApp仓库和.sol文件可以看到进行中的有趣东西。这里有一个DApp大列表：<a href="http://dapps.ethercasts.com/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">dapps.ethercasts.com</a>，不过其中一些项目已经过时。<a href="http://ether.fund/contracts" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Ether.fund/contracts</a>上有一些Solidity和Serpent写的合约示例，但是不清楚这些例子有没有经过测试或者正确性验证。11月12日的<a href="https://devcon.ethereum.org/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">开发者大会&ETH;&Xi;VCON1</a>将会有一整天的DApp主题演讲。</p>
<h3 id="部署智能合约的流程" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">部署智能合约的流程</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">流程如下：</p>
<ol style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">启动一个<strong style="box-sizing: inherit;">以太坊节点</strong>&nbsp;(例如geth或者testrpc)。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">使用solc*<em style="box-sizing: inherit;">编译</em>*智能合约。 =&gt; 获得二进制代码。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">将编译好的合约<strong style="box-sizing: inherit;">部署</strong>到网络。（这一步会消耗以太币，还需要使用你的节点的默认地址或者指定地址来给合约签名。） =&gt; 获得合约的区块链地址和ABI（合约接口的JSON表示，包括变量，事件和可以调用的方法）。(译注：作者在这里把ABI与合约接口弄混了。ABI是合约接口的二进制表示。)</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">用web3.js提供的JavaScript API来<strong style="box-sizing: inherit;">调用</strong>合约。（根据调用的类型有可能会消耗以太币。）</li>
</ol>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">下图详细描绘了这个流程：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/1fc96327c8a1d60c8dc16f8ec1a2fe5d.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">你的DApp可以给用户提供一个界面先部署所需合约再使用之（如图1到4步），也可以假设合约已经部署了（常见方法），直接从使用合约（如图第6步）的界面开始。</p>
<h2 id="第三部分. 编程" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">第三部分. 编程</h2>
<h3 id="在Truffle中进行测试" style="box-sizing: inherit; margin: 0px 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">在Truffle中进行测试</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><a href="https://github.com/consensys/truffle" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Truffle</a>用来做智能合约的测试驱动开发(TDD)非常棒，我强烈推荐你在学习中使用它。它也是学习使用JavaScript Promise的一个好途径，例如deferred和异步调用。Promise机制有点像是说&ldquo;做这件事，如果结果是这样，做甲，如果结果是那样，做乙... 与此同时不要在那儿干等着结果返回，行不？&rdquo;。Truffle使用了包装web3.js的一个JS Promise框架<a href="https://github.com/ConsenSys/ether-pudding" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Pudding</a>（因此它为为你安装web3.js）。(译注：Promise是流行于JavaScript社区中的一种异步调用模式。它很好的封装了异步调用，使其能够灵活组合，而不会陷入callback hell.)</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Transaction times.</strong>&nbsp;Promise对于DApp非常有用，因为交易写入以太坊区块链需要大约12-15秒的时间。即使在测试网络上看起来没有那么慢，在正式网络上却可能会要更长的时间（例如你的交易可能用光了Gas，或者被写入了一个孤儿块）。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">下面让我们给一个简单的智能合约写测试用例吧。</p>
<h3 id="使用Truffle" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">使用Truffle</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">首先确保你 1.安装好了<a href="https://github.com/ethereum/webthree-umbrella/wiki" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">solc</a>以及 2.<a href="https://github.com/ConsenSys/eth-testrpc" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">testrpc</a>。（testrpc需要<a href="https://www.python.org/downloads/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Python</a>和<a href="https://pip.pypa.io/en/stable/installing/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">pip</a>。如果你是Python新手，你可能需要用<a href="http://docs.python-guide.org/en/latest/dev/virtualenvs/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">virtualenv</a>来安装，这可以将Python程序库安装在一个独立的环境中。）</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">接下来安装 3.<a href="https://github.com/ConsenSys/truffle" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Truffle</a>（你可以使用<a href="https://docs.npmjs.com/getting-started/installing-node" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">NodeJS's npm</a>来安装：<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">npm install -g truffle</code>,&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">-g</code>开关可能会需要sudo）。安装好之后，在命令行中输入<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle list</code>来验证安装成功。然后创建一个新的项目目录（我把它命名为'conference'），进入这个目录，运行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle init</code>。该命令会建立如下的目录结构：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/57b9fb67369c190fa455766ab5f6556f.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">现在让我们在<strong style="box-sizing: inherit;">另一个终端</strong>里通过执行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">testrpc</code>来启动一个节点（你也可以用geth）：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/a7d19ebfb8d027b65384c532770b3ba8.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">回到之前的终端中，输入<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle deploy</code>。这条命令会部署之前<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle init</code>产生的模板合约到网络上。任何你可能遇到的错误信息都会在testrpc的终端或者执行truffle的终端中输出。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">在开发过程中你随时可以使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle compile</code>命令来确认你的合约可以正常编译（或者使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">solc YourContract.sol</code>），<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle deploy</code>来编译和部署合约，最后是<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle test</code>来运行智能合约的测试用例。</p>
<h3 id="第一个合约" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">第一个合约</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">下面是一个针对会议的智能合约，通过它参会者可以买票，组织者可以设置参会人数上限，以及退款策略。本文涉及的所有代码都可以在这个<a href="https://github.com/eshon/conference" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">代码仓库</a>找到。</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">contract Conference {   address public organizer;   mapping (address =&gt; uint) public registrantsPaid;   uint public numRegistrants;   uint public quota;    event Deposit(address _from, uint _amount);  // so you can log these events   event Refund(address _to, uint _amount);     function Conference() { // Constructor     organizer = msg.sender;     quota = 500;     numRegistrants = 0;   }   function buyTicket() public returns (bool success) {     if (numRegistrants &gt;= quota) { return false; }     registrantsPaid[msg.sender] = msg.value;     numRegistrants++;     Deposit(msg.sender, msg.value);     return true;   }   function changeQuota(uint newquota) public {     if (msg.sender != organizer) { return; }     quota = newquota;   }   function refundTicket(address recipient, uint amount) public {     if (msg.sender != organizer) { return; }     if (registrantsPaid[recipient] == amount) {        address myAddress = this;       if (myAddress.balance &gt;= amount) {          recipient.send(amount);         registrantsPaid[recipient] = 0;         numRegistrants--;         Refund(recipient, amount);       }     }   }   function destroy() { // so funds not locked in contract forever     if (msg.sender == organizer) {        suicide(organizer); // send funds to organizer     }   } }</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">接下来让我们部署这个合约。（注意：本文写作时我使用的是Mac OS X 10.10.5, solc 0.1.3+ (通过brew安装)，Truffle v0.2.3, testrpc v0.1.18 (使用venv)）</p>
<h3 id="部署合约" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">部署合约</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/93ece58476d59db60d3c60657d5baa2d.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">(译注：图中步骤翻译如下：）</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">使用truffle部署智能合约的步骤：<br style="box-sizing: inherit;" />
1.&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle init</code>&nbsp;(在新目录中) =&gt; 创建truffle项目目录结构<br style="box-sizing: inherit;" />
2. 编写合约代码，保存到<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contracts/YourContractName.sol</code>文件。<br style="box-sizing: inherit;" />
3. 把合约名字加到<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">config/app.json</code>的'contracts'部分。<br style="box-sizing: inherit;" />
4. 启动以太坊节点（例如在另一个终端里面运行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">testrpc</code>）。<br style="box-sizing: inherit;" />
5.&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle deploy</code>（在truffle项目目录中)</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">添加一个智能合约。</strong>&nbsp;在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle init</code>执行后或是一个现有的项目目录中，复制粘帖上面的会议合约到<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contracts/Conference.sol</code>文件中。然后打开<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">config/app.json</code>文件，把'Conference'加入'deploy'数组中。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/62922e726f12f928492d4a647951f72c.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">启动testrpc。</strong>&nbsp;在另一个终端中启动<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">testrpc</code>。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">编译或部署。</strong>&nbsp;执行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle compile</code>看一下合约是否能成功编译，或者直接<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle deploy</code>一步完成编译和部署。这条命令会把部署好的合约的地址和ABI（应用接口）加入到配置文件中，这样之后的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle test</code>和<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle build</code>步骤可以使用这些信息。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">出错了？</strong>&nbsp;编译是否成功了？记住，错误信息即可能出现在testrpc终端也可能出现在truffle终端。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">重启节点后记得重新部署！</strong>&nbsp;如果你停止了testrpc节点，下一次使用任何合约之前切记使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle deploy</code>重新部署。testrpc在每一次重启之后都会回到完全空白的状态。</p>
<h3 id="合约代码解读" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">合约代码解读</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">让我们从智能合约头部的变量声明开始：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">address public organizer; mapping (address =&gt; uint) public registrantsPaid; uint public numRegistrants; uint public quota;</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">address.</strong>&nbsp;地址类型。第一个变量是会议组织者的钱包地址。这个地址会在合约的构造函数<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">function Conference()</code>中被赋值。很多时候也称呼这种地址为'owner'（所有人）。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">uint.</strong>&nbsp;无符号整型。区块链上的存储空间很紧张，保持数据尽可能的小。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">public.</strong>&nbsp;这个关键字表明变量可以被合约之外的对象使用。<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">private</code>修饰符则表示变量只能被本合约(或者衍生合约)内的对象使用。如果你想要在测试中通过web3.js使用合约中的某个变量，记得把它声明为<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">public</code>。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Mapping或数组。</strong>（译注：Mapping类似Hash, Directory等数据类型，不做翻译。）在Solidity加入数组类型之前，大家都使用类似<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">mapping (address =&gt; uint)</code>的Mapping类型。这个声明也可以写作<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">address registrantsPaid[]</code>，不过Mapping的存储占用更小(smaller footprint)。这个Mapping变量会用来保存参加者（用他们的钱包地址表示）的付款数量以便在退款时使用。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">关于地址。</strong>&nbsp;你的客户端（比如testrpc或者geth）可以生成一个或多个账户/地址。testrpc启动时会显示10个可用地址：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/26c59b073b0d405cd482e2690e47639a.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">第一个地址,&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">accounts[0]</code>，是发起调用的默认地址，如果没有特别指定的话。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">组织者地址 vs. 合约地址。</strong>&nbsp;部署好的合约会在区块链上拥有自己的地址（与组织者拥有的是不同的地址）。在Solidity合约中可以使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">this</code>来访问这个合约地址，正如<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">refundTicket</code>函数所展示的：<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">address myAddress = this;</code></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Suicide, Solidity的好东西。</strong>（译注：<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">suicide</code>意为'自杀', 为Solidity提供的关键字，不做翻译。）转给合约的资金会保存于合约（地址）中。最终这些资金通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">destroy</code>函数被释放给了构造函数中设置的组织者地址。这是通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">suicide(orgnizer);</code>这行代码实现的。没有这个，资金可能被永远锁定在合约之中（reddit上有些人就遇到过），因此如果你的合约会接受资金一定要记得在合约中使用这个方法！</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">如果想要模拟另一个用户或者对手方（例如你是卖家想要模拟一个买家），你可以使用可用地址数组中另外的地址。假设你要以另一个用户，<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">accounts[1]</code>, 的身份来买票，可以通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">from</code>参数设置：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">conference.buyTicket({ from: accounts[1], value: some_ticket_price_integer });</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">函数调用可以是交易。</strong>&nbsp;改变合约状态（修改变量值，添加记录，等等）的函数调用本身也是转账交易，隐式的包含了发送人和交易价值。因此web3.js的函数调用可以通过指定<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">{ from: __, value: __ }</code>参数来发送以太币。在Solidity合约中，你可以通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">msg.sender</code>和<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">msg.value</code>来获取这些信息：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">function buyTicket() public {     ...     registrantsPaid[msg.sender] = msg.value;     ... }</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">事件(Event)。</strong>&nbsp;可选的功能。合约中的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">Deposit</code>（充值）和<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">Send</code>（发送）事件是会被记录在以太坊虚拟机日志中的数据。它们实际上没有任何作用，但是用事件(Event)把交易记录进日志是好的做法。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">好了，现在让我们给这个智能合约写一个测试，来确保它能工作。</p>
<h3 id="写测试" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">写测试</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">把项目目录<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">test/</code>中的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">example.js</code>文件重命名为<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">conference.js</code>，文件中所有的'Example'替换为'Conference'。</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">contract</span><span class="p" style="box-sizing: inherit;">(</span><span class="s1" style="box-sizing: inherit; color: rgb(208, 16, 64);">'Conference'</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>   <span class="nx" style="box-sizing: inherit;">it</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;should assert true&quot;</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>     <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">conference</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">at</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">deployed_address</span><span class="p" style="box-sizing: inherit;">);</span>     <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">isTrue</span><span class="p" style="box-sizing: inherit;">(</span><span class="kc" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">true</span><span class="p" style="box-sizing: inherit;">);</span>     <span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">();</span>   <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// stops tests at this point</span>   <span class="p" style="box-sizing: inherit;">});</span> <span class="p" style="box-sizing: inherit;">});</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">在项目根目录下运行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle test</code>，你应该看到测试通过。在上面的测试中truffle通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">Conference.deployed_address</code>获得合约部署在区块链上的地址。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">让我们写一个测试来初始化一个新的Conference，然后检查变量都正确赋值了。将<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">conference.js</code>中的测试代码替换为：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">contract</span><span class="p" style="box-sizing: inherit;">(</span><span class="s1" style="box-sizing: inherit; color: rgb(208, 16, 64);">'Conference'</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>   <span class="nx" style="box-sizing: inherit;">it</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Initial conference settings should match&quot;</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>     <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">conference</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">at</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">deployed_address</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// same as previous example up to here</span>     <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">new</span><span class="p" style="box-sizing: inherit;">({</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">]</span>  <span class="p" style="box-sizing: inherit;">})</span>     <span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span><span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>       <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">().</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>           <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>             <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">500</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Quota doesn't match!&quot;</span><span class="p" style="box-sizing: inherit;">);</span>            <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>             <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">numRegistrants</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">();</span>           <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">num</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>             <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">num</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Registrants should be zero!&quot;</span><span class="p" style="box-sizing: inherit;">);</span>             <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">organizer</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">();</span>           <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">organizer</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>             <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">organizer</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">],</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Owner doesn't match!&quot;</span><span class="p" style="box-sizing: inherit;">);</span>             <span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">();</span>   <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// to stop these tests earlier, move this up</span>         <span class="p" style="box-sizing: inherit;">}).</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">catch</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="p" style="box-sizing: inherit;">}).</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">catch</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">);</span>     <span class="p" style="box-sizing: inherit;">});</span>   <span class="p" style="box-sizing: inherit;">});</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">构造函数。</strong>&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">Conference.new({ from: accounts[0] })</code>通过调用合约构造函数创造了一个新的Conference实例。由于不指定<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">from</code>时会默认使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">accounts[0]</code>，它其实可以被省略掉：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">Conference.new({ from: accounts[0] }); // 和Conference.new()效果相同</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Promise.</strong>&nbsp;代码中的那些<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">then</code>和<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">return</code>就是Promise。它们的作用写成一个深深的嵌套调用链的话会是这样：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">numRegistrants</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">().</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>   <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">num</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>     <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">num</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Registrants should be zero!&quot;</span><span class="p" style="box-sizing: inherit;">);</span>     <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">organizer</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">().</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>      <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">organizer</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>         <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">organizer</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">],</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Owner doesn't match!&quot;</span><span class="p" style="box-sizing: inherit;">);</span>         <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>           <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(...))</span>             <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>               <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(...))</span>             <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// Because this would get hairy...</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">Promise减少嵌套，使代码变得扁平，允许调用异步返回，并且简化了表达&ldquo;成功时做这个&rdquo;和&ldquo;失败时做那个&rdquo;的语法。Web3.js通过<a href="https://github.com/ethereum/wiki/wiki/JavaScript-API#using-callbacks" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">回调函数</a>实现异步调用，因此你不需要等到交易完成就可以继续执行前端代码。Truffle借助了用Promise封装web3.js的一个框架，叫做<a href="https://github.com/ConsenSys/ether-pudding" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Pudding</a>，这个框架本身又是基于<a href="http://ricostacruz.com/cheatsheets/bluebird.html" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Bluebird</a>的，它支持Promise的高级特性。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">call.</strong>&nbsp;我们使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">call</code>来检查变量的值，例如<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">conference.quota.call().then(...</code>，还可以通过传参数，例如<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">call(0)</code>, 来获取mapping在index 0处的元素。Solidity的文档说这是一种特殊的&ldquo;消息调用&rdquo;因为 1.不会为矿工记录和 2.不需要从钱包账户/地址发起（因此它没有被账户持有者私钥做签名）。另一方面，交易/事务(Transaction)会被矿工记录，必须来自于一个账户（也就是有签名），会被记录到区块链上。对合约中数据做的任何修改都是交易。仅仅是检查一个变量的值则不是。因此在读取变量时不要忘记加上<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">call()</code>！否则会发生奇怪的事情。（此外如果在读取变量是遇到问题别忘记检查它是否是<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">public</code>。）<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">call()</code>也能用于调用不是交易的函数。如果一个函数本来是交易，但你却用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">call()</code>来调用，则不会在区块链上产生交易。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">断言。</strong>&nbsp;标准JS测试中的断言（如果你不小心拼成了复数形式'asserts'，truffle会报错，让你一头雾水），<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">assert.equal</code>是最常用的，其他类型的断言可以在<a href="http://chaijs.com/api/assert/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Chai的文档</a>中找到。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">再一次运行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle test</code>确保一切工作正常。</p>
<h3 id="测试合约函数调用" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">测试合约函数调用</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">现在我们测试一下改变<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">quote</code>变量的函数能工作。在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">tests/conference.js</code>文件的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contract('Conference', function(accounts) {...};)</code>的函数体中添加如下测试用例：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">it</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Should update quota&quot;</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>   <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">c</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">at</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">deployed_address</span><span class="p" style="box-sizing: inherit;">);</span>    <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">new</span><span class="p" style="box-sizing: inherit;">({</span><span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">]</span> <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>     <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>       <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">().</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>          <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>            <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">500</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Quota doesn't match!&quot;</span><span class="p" style="box-sizing: inherit;">);</span>          <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>            <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">changeQuota</span><span class="p" style="box-sizing: inherit;">(</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">300</span><span class="p" style="box-sizing: inherit;">);</span>         <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">result</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>  <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// result here is a transaction hash</span>           <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">result</span><span class="p" style="box-sizing: inherit;">);</span>  <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// if you were to print this out it&rsquo;d be long hex - the transaction hash</span>           <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">()</span>         <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>            <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">quota</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">300</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;New quota is not correct!&quot;</span><span class="p" style="box-sizing: inherit;">);</span>           <span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">();</span>         <span class="p" style="box-sizing: inherit;">}).</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">catch</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">);</span>     <span class="p" style="box-sizing: inherit;">}).</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">catch</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">);</span> <span class="p" style="box-sizing: inherit;">});</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">这里的新东西是调用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">changeQuota</code>函数的那一行。<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">console.log</code>对于调试很有用，用它能在运行truffle的终端中输出信息。在关键点插入<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">console.log</code>可以查看执行到了哪一步。记得把Solidity合约中<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">changeQuota</code>函数被声明为<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">public</code>，否则你不能调用它：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">  function changeQuota(uint newquota) public {  }</code></pre>
<h3 id="测试交易" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">测试交易</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">现在让我们调用一个需要发起人发送资金的函数。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Wei.</strong>&nbsp;以太币有很多种单位（这里有个很有用的<a href="http://ether.fund/tool/converter" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">转换器</a>）,在合约中通常用的是Wei，最小的单位。Web3.js提供了在各单位与Wei之间互相转换的便利方法，形如<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">web3.toWei(.05, 'ether')</code>。JavaScript在处理很大的数字时有问题，因此web3.js使用了<a href="https://github.com/MikeMcl/bignumber.js/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">程序库BigNumber</a>，并建议在代码各处都以Wei做单位，直到要给用户看的时候（<a href="https://github.com/ethereum/wiki/wiki/JavaScript-API#a-note-on-big-numbers-in-web3js" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">文档</a>。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">账户余额。</strong>&nbsp;Web3.js提供了许多提供方便的<a href="https://github.com/ethereum/wiki/wiki/JavaScript-API#web3-javascript-%C3%90app-api-reference" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">方法</a>，其中另一个会在下面测试用到的是<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">web3.eth.getBalance(some_address)</code>。记住发送给合约的资金会由合约自己持有直到调用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">suicide</code>。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contract(Conference, function(accounts) {...};)</code>的函数体中插入下面的测试用例。在高亮显示的方法中，测试用例让另一个用户(<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">accounts[1]</code>)以<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">ticketPrice</code>的价格买了一张门票。然后它检查合约的账户余额增加了<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">ticketPrice</code>，以及购票用户被加入了参会者列表。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">这个测试中的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">buyTicket</code>是一个交易函数：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">it</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Should let you buy a ticket&quot;</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>   <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">c</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">at</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">deployed_address</span><span class="p" style="box-sizing: inherit;">);</span>    <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">new</span><span class="p" style="box-sizing: inherit;">({</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">]</span> <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>     <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>       <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">toWei</span><span class="p" style="box-sizing: inherit;">(.</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">05</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s1" style="box-sizing: inherit; color: rgb(208, 16, 64);">'ether'</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">initialBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>        <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">buyTicket</span><span class="p" style="box-sizing: inherit;">({</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">],</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">value</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span> <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>         <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>           <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">newBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>           <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">difference</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">newBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">-</span> <span class="nx" style="box-sizing: inherit;">initialBalance</span><span class="p" style="box-sizing: inherit;">;</span>           <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">difference</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Difference should be what was sent&quot;</span><span class="p" style="box-sizing: inherit;">);</span>           <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">numRegistrants</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">();</span>       <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span><span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">num</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>           <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">num</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;there should be 1 registrant&quot;</span><span class="p" style="box-sizing: inherit;">);</span>           <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">registrantsPaid</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">call</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">]);</span>       <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span><span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">amount</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>           <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">amount</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">(),</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Sender's paid but is not listed&quot;</span><span class="p" style="box-sizing: inherit;">);</span>           <span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">();</span>       <span class="p" style="box-sizing: inherit;">}).</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">catch</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">);</span>   <span class="p" style="box-sizing: inherit;">}).</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">catch</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">);</span> <span class="p" style="box-sizing: inherit;">});</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">交易需要签名。</strong>&nbsp;和之前的函数调用不同，这个调用是一个会发送资金的交易，在这种情况下购票用户(<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">accounts[1]</code>)会用他的私钥对<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">buyTicket()</code>调用做签名。（在geth中用户需要在发送资金之前通过输入密码来批准这个交易或是解锁钱包的账户。）</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">toNumber().</strong>&nbsp;有时我们需要把Solidity返回的十六进制结果转码。如果结果可能是个很大的数字可以用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">web3.toBigNumber(numberOrHexString)</code>来处理因为JavaScript直接对付大数要糟。</p>
<h3 id="测试包含转账的合约" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">测试包含转账的合约</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">最后，为了完整性，我们确认一下<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">refundTicket</code>方法能正常工作，而且只有会议组织者能调用。下面是测试用例：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">it</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Should issue a refund by owner only&quot;</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>   <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">c</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">at</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">deployed_address</span><span class="p" style="box-sizing: inherit;">);</span>    <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">new</span><span class="p" style="box-sizing: inherit;">({</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">]</span> <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>     <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>       <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">toWei</span><span class="p" style="box-sizing: inherit;">(.</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">05</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s1" style="box-sizing: inherit; color: rgb(208, 16, 64);">'ether'</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">initialBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>         <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">buyTicket</span><span class="p" style="box-sizing: inherit;">({</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">],</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">value</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span> <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>         <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>           <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">newBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>           <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">difference</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">newBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">-</span> <span class="nx" style="box-sizing: inherit;">initialBalance</span><span class="p" style="box-sizing: inherit;">;</span>           <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">difference</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Difference should be what was sent&quot;</span><span class="p" style="box-sizing: inherit;">);</span>  <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// same as before up to here</span>           <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// Now try to issue refund as second user - should fail</span>           <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">refundTicket</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">],</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span><span class="p" style="box-sizing: inherit;">,</span> <span class="p" style="box-sizing: inherit;">{</span><span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">]});</span>           <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>           <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>             <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">balance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>             <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">toBigNumber</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">balance</span><span class="p" style="box-sizing: inherit;">),</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Balance should be unchanged&quot;</span><span class="p" style="box-sizing: inherit;">);</span>             <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// Now try to issue refund as organizer/owner - should work</span>             <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">refundTicket</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">],</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span><span class="p" style="box-sizing: inherit;">,</span> <span class="p" style="box-sizing: inherit;">{</span><span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">]});</span>           <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>           <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>             <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">postRefundBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>             <span class="nx" style="box-sizing: inherit;">assert</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">equal</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">postRefundBalance</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nx" style="box-sizing: inherit;">initialBalance</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Balance should be initial balance&quot;</span><span class="p" style="box-sizing: inherit;">);</span>             <span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">();</span>         <span class="p" style="box-sizing: inherit;">}).</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">catch</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">);</span>     <span class="p" style="box-sizing: inherit;">}).</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">catch</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">done</span><span class="p" style="box-sizing: inherit;">);</span>  <span class="p" style="box-sizing: inherit;">});</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">这个测试用例覆盖的Solidity函数如下：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">function refundTicket(address recipient, uint amount) public returns (bool success) {   if (msg.sender != organizer) { return false; }   if (registrantsPaid[recipient] == amount) {      address myAddress = this;     if (myAddress.balance &gt;= amount) {        recipient.send(amount);       Refund(recipient, amount);       registrantsPaid[recipient] = 0;       numRegistrants--;       return true;     }   }   return false; }</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">合约中发送以太币。</strong>&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">address myAddress = this</code>展示了如何获取该会议合约实例的地址，以变接下来检查这个地址的余额（或者直接使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">this.balance</code>）。合约通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">recipient.send(amount)</code>方法把资金发回了购票人。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">交易无法返回结果给web3.js.</strong>&nbsp;注意这一点！<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">refundTicket</code>函数会返回一个布尔值，但是这在测试中无法检查。因为这个方法是一个交易函数（会改变合约内数据或是发送以太币的调用），而web3.js得到的交易运行结果是一个交易哈希（如果打印出来是一个长长的十六进制/怪怪的字符串）。既然如此为什么还要让<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">refundTicket</code>返回一个值？因为在Solidity合约内可以读到这个返回值，例如当另一个合约调用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">refundTicket()</code>的时候。也就是说Solidity合约可以读取交易运行的返回值，而web3.js不行。另一方面，在web3.js中你可以用事件机制（Event, 下文会解释）来监控交易运行，而合约不行。合约也无法通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">call()</code>来检查交易是否修改了合约内变量的值。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">关于sendTransaction().</strong>&nbsp;当你通过web3.js调用类似<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">buyTicket()</code>或者<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">refundTicket()</code>的交易函数时（使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">web3.eth.sendTransaction</code>），交易并不会立即执行。事实上交易会被提交到矿工网络中，交易代码直到其中一位矿工产生一个新区块把交易记录进区块链之后才执行。因此你必须等交易进入区块链并且同步回本地节点之后才能验证交易执行的结果。用testrpc的时候可能看上去是实时的，因为测试环境很快，但是正式网络会比较慢。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">事件/Event.</strong>&nbsp;在web3.js中你应该监听<a href="https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-events" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">事件</a>而不是返回值。我们的智能合约示例定义了这些事件：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">event Deposit(address _from, uint _amount); event Refund(address _to, uint _amount);</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">它们在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">buyTicket()</code>和<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">refundTicket()</code>中被触发。触发时你可以在testrpc的输出中看到日志。要监听事件，你可以使用web.js监听器(listener)。在写本文时我还不能在truffle测试中记录事件，但是在应用中没问题：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">new</span><span class="p" style="box-sizing: inherit;">({</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">]</span> <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>   <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>     <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">event</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">allEvents</span><span class="p" style="box-sizing: inherit;">().</span><span class="nx" style="box-sizing: inherit;">watch</span><span class="p" style="box-sizing: inherit;">({},</span> <span class="s1" style="box-sizing: inherit; color: rgb(208, 16, 64);">''</span><span class="p" style="box-sizing: inherit;">);</span> <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// or use conference.Deposit() or .Refund()</span>     <span class="nx" style="box-sizing: inherit;">event</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">watch</span><span class="p" style="box-sizing: inherit;">(</span><span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span> <span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">error</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nx" style="box-sizing: inherit;">result</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>       <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">if</span> <span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">error</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>         <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Error: &quot;</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">+</span> <span class="nx" style="box-sizing: inherit;">error</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="p" style="box-sizing: inherit;">}</span> <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">else</span> <span class="p" style="box-sizing: inherit;">{</span>         <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Event: &quot;</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">+</span> <span class="nx" style="box-sizing: inherit;">result</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">event</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="p" style="box-sizing: inherit;">}</span>     <span class="p" style="box-sizing: inherit;">});</span>     <span class="c1" style="box-sizing: inherit; color: rgb(153, 153, 136); font-style: italic;">// ...</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">过滤器/Filter.</strong>&nbsp;监听所有事件可能会产生大量的轮询，作为替代可以使用过滤器。它们可以更灵活的开始或是停止对事件的监听。更多过滤器的信息可查看<a href="https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethfilter" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Solidity文档</a>。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">总的来说，使用事件和过滤器的组合比检查变量消耗的Gas更少，因而在验证正式网络的交易运行结果时非常有用。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">Gas.</strong>&nbsp;（译注：以太坊上的燃料，因为代码的执行必须消耗Gas。直译为汽油比较突兀，故保留原文做专有名词。）直到现在我们都没有涉及Gas的概念，因为在使用testrpc时通常不需要显式的设置。当你转向geth和正式网络时会需要。在交易函数调用中可以在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">{from: __, value: __, gas: __}</code>对象内设置Gas参数。Web3.js提供了<a href="https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgasprice" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">web3.eth.gasPrice</code></a>调用来获取当前Gas的价格，Solidity编译器也提供了一个参数让你可以从命令行获取合约的Gas开销概要：<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">solc --gas YouContract.sol</code>。下面是<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">Conference.sol</code>的结果：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/afa43126d926ed3db1915718900c69c7.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<h3 id="为合约创建DApp界面" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">为合约创建DApp界面</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><em style="box-sizing: inherit;">下面的段落会假设你没有网页开发经验。</em></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">上面编写的测试用例用到的都是在前端界面中也可以用的方法。你可以把前端代码放到<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">app/</code>目录中，运行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle build</code>之后它们会和合约配置信息一起编译输出到<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">build/</code>目录。在开发时可以使用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle watch</code>命令在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">app/</code>有任何变动时自动编译输出到<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">build/</code>目录。然后在浏览器中刷新页面即可看到<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">build/</code>目录中的最新内容。（<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle serve</code>可以启动一个基于<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">build/</code>目录的网页服务器。）</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">app/</code>目录中有一些样板文件帮助你开始：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/a6a8374e2ee98c702455fdfa93b5e117.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">index.html</code>会加载<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">app.js</code>：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/91153d00abd7361d997276e252a3ac75.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">因此我们只需要添加代码到<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">app.js</code>就可以了。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">默认的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">app.js</code>会在浏览器的console(控制台)中输出一条&quot;Hello from Truffle!&quot;的日志。在项目根目录中运行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle watch</code>，然后在浏览器中打开<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">build/index.html</code>文件，再打开浏览器的console就可以看到。（大部分浏览器例如Chrome中，单击右键 -&gt; 选择Inspect Element然后切换到Console即可。）</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/18b1dd84faa4aa16a841f6fe7ab0093e.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">app.js</code>中，添加一个在页面加载时会运行的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">window.onload</code>调用。下面的代码会确认web3.js已经正常载入并显示所有可用的账户。（注意：你的testrpc节点应该保持运行。）</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nb" style="box-sizing: inherit; color: rgb(0, 134, 179);">window</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">onload</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>   <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">accounts</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">;</span>   <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">);</span> <span class="p" style="box-sizing: inherit;">}</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">看看你的浏览器console中看看是否打印出了一组账户地址。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">现在你可以从<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">tests/conference.js</code>中复制一些代码过来（去掉只和测试有关的断言），将调用返回的结果输出到console中以确认代码能工作。下面是个例子：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nb" style="box-sizing: inherit; color: rgb(0, 134, 179);">window</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">onload</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>   <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">accounts</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">;</span>   <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">c</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">at</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">deployed_address</span><span class="p" style="box-sizing: inherit;">);</span>    <span class="nx" style="box-sizing: inherit;">Conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">new</span><span class="p" style="box-sizing: inherit;">({</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">]</span> <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>     <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>      <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">toWei</span><span class="p" style="box-sizing: inherit;">(.</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">05</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s1" style="box-sizing: inherit; color: rgb(208, 16, 64);">'ether'</span><span class="p" style="box-sizing: inherit;">);</span>     <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">initialBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>      <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;The conference's initial balance is: &quot;</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">+</span> <span class="nx" style="box-sizing: inherit;">initialBalance</span><span class="p" style="box-sizing: inherit;">);</span>      <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">buyTicket</span><span class="p" style="box-sizing: inherit;">({</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">],</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">value</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span> <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>       <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>         <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">newBalance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>         <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;After someone bought a ticket it's: &quot;</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">+</span> <span class="nx" style="box-sizing: inherit;">newBalance</span><span class="p" style="box-sizing: inherit;">);</span>         <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">return</span> <span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">refundTicket</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">],</span> <span class="nx" style="box-sizing: inherit;">ticketPrice</span><span class="p" style="box-sizing: inherit;">,</span> <span class="p" style="box-sizing: inherit;">{</span><span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">]});</span>       <span class="p" style="box-sizing: inherit;">}).</span><span class="nx" style="box-sizing: inherit;">then</span><span class="p" style="box-sizing: inherit;">(</span>         <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>             <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">balance</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">getBalance</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">conference</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">).</span><span class="nx" style="box-sizing: inherit;">toNumber</span><span class="p" style="box-sizing: inherit;">();</span>           <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;After a refund it's: &quot;</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">+</span> <span class="nx" style="box-sizing: inherit;">balance</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="p" style="box-sizing: inherit;">});</span>   <span class="p" style="box-sizing: inherit;">});</span> <span class="p" style="box-sizing: inherit;">};</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">上面的代码应该输出如下：</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/f093c01e94c9d56b8f58202edb42a27e.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">(console输出的warning信息可忽略。)</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">现在起你就可以使用你喜欢的任何前端工具，jQuery, ReactJS, Meteor, Ember, AngularJS，等等等等，在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">app/</code>目录中构建可以与以太坊智能合约互动的DApp界面了！接下来我们给出一个极其简单基于jQuery的界面作为示例。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><img src="http://ethfans.org/uploads/photo/2015/a85ed594ffaceef763fb249508d855eb.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto; display: block; margin: 0px auto; box-shadow: rgb(207, 207, 207) 1px 1px 4px 1px;" /></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">这里是<a href="https://github.com/eshon/conference/blob/master/app/index.html" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">index.html的代码</a>，这里是<a href="https://github.com/eshon/conference/blob/master/app/javascripts/app.js" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">app.js的代码</a>。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">通过界面测试了智能合约之后我意识到最好加入检查以保证相同的用户不能注册两次。另外由于现在是运行在testrpc节点上，速度很快，最好是切换到geth节点并确认交易过程依然能及时响应。否则的话界面上就应该显示提示信息并且在处理交易时禁用相关的按钮。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">尝试geth.</strong>&nbsp;如果你使用<a href="https://github.com/ethereum/go-ethereum/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">geth</a>, 可以尝试以下面的命令启动 - 在我这儿(geth v1.2.3)工作的很好：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">build/bin/geth --rpc --rpcaddr=&quot;0.0.0.0&quot; --rpccorsdomain=&quot;*&quot; --mine --unlock='0 1' --verbosity=5 --maxpeers=0 --minerthreads='4'  --networkid '12345' --genesis test-genesis.json</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">这条命令解锁了两个账户,&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">0</code>和<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">1</code>。1. 在geth控制台启动后你可能需要输入这两个账户的密码。2. 你需要在<a href="https://github.com/ethereum/go-ethereum/wiki/Connecting-to-the-network#custom-networks" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">test-genesis.json</code></a>文件里面的'alloc'配置中加入你的这两个账户，并且给它们充足的资金。3. 最后，在创建合约实例时加上gas参数：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">Conference.new({from: accounts[0], gas: 3141592})</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">然后把整个<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle deploy</code>,&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">truffle build</code>流程重来一遍。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">教程中的代码。</strong>&nbsp;在这篇基础教程中用到的所有代码都可以在这个<a href="https://github.com/eshon/conference" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">代码仓库</a>中找到。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">自动为合约生成界面。</strong>&nbsp;<a href="https://github.com/SilentCicero" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">SilentCicero</a>制作了一个叫做<a href="http://dapp-builder.meteor.com/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">DApp Builder</a>的工具，可以用Solidity合约自动生成HTML, jQuery和web.js的代码。这种模式也正在被越来越多的正在开发中的开发者工具采用。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">教程到此结束！</strong>&nbsp;最后一章我们仅仅学习了一套工具集，主要是Truffle和testrpc. 要知道即使在ConsenSys内部，不同的开发者使用的工具和框架也不尽相同。你可能会发现更适合你的工具，这里所说的工具可能很快也会有改进。但是本文介绍的工作流程帮助我走上了DApp开发之路。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">(⊙&omega;⊙) wonk wonk</p>
<p style="box-sizing: inherit; margin-bottom: 0px; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><em style="box-sizing: inherit;">感谢Joseph Chow的校阅和建议，Christian Lundkvist, Daniel Novy, Jim Berry, Peter Borah和Tim Coulter帮我修改文字和debug，以及Tim Coulter, Nchinda Nchinda和Mike Goldin对DApp前端步骤图提供的帮助。</em></p>
<p style="box-sizing: inherit; margin-bottom: 0px;"><span style="box-sizing: inherit; font-size: 16px; line-height: 27.2px;"><font color="#333333" face="Source Sans Pro, Helvetica Neue, Helvetica, Arial, Rhythm Heiti, sans-serif"><em>http://ethfans.org/posts/101-noob-intro</em></font></span></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-875-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 22:51</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-874-1.html</guid>
			<title>区块链开发（一）搭建基于以太坊go-ethereum的私有链环境</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">通过各方资料了解学习之后，决定自己开始搭建基于以太坊Go-ethereum的私有链环境。由于本人的电脑系统为win8，为避免window环境出现过多莫名其妙的问题，特意通过vm搭建了一台ubuntu16.04版本的虚拟系统。以下内容均基于ubuntu16.04系统。</span></p>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">go-ethereum客户端</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">下载地址&amp;参考手册</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">首先，可以查看一下go-ethereum项目在Git上的地址：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">https://github.com/ethereum/Go-ethereum</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">可以在点击项目上的wiki标签，也可以通过一下地址访问wiki：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">https://github.com/ethereum/Go-ethereum/wiki/Building-Ethereum</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">在wiki页面选择ubuntu系统的安装说明，也可以直接访问下面链接：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">ubuntu下安装命令</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">打开命令行窗口，或通过快捷键CTL+ALT+T，依次输入以下命令，即可安装成功：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">sudo apt-get install software-properties-common</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">sudo add-apt-repository -y ppa:ethereum/ethereum</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">sudo add-apt-repository -y ppa:ethereum/ethereum-dev</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">sudo apt-get update</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">sudo apt-get install ethereum</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">PS：如果安装过程中需要依赖其他组件，则先安装其他组件。另外，在ubuntu16.04版本，sudo apt-get install命令可精简为sudo apt install。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">安装测试</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">安装完成之后在命令行输入：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">geth --help</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">如果现实出命令行各种参数提示信息，则说明安装成功。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">创世块</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">在以上安装成功之后，直接启动，即可连接公有链。现在通过配置创世块来创建私有链。同一个网络中，创世块必须是一样的，否则无法联通。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">创建一个eth的根目录，在根目录下新建创世块json文件piccgenesis.json。内容如下：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">{</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;nonce&quot;:&quot;0x0000000000000042&quot;,</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;mixhash&quot;:&quot;0x0000000000000000000000000000000000000000000000000000000000000000&quot;,</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;difficulty&quot;: &quot;0x4000&quot;,</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;alloc&quot;: {},</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;coinbase&quot;:&quot;0x0000000000000000000000000000000000000000&quot;,</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;timestamp&quot;: &quot;0x00&quot;,</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;parentHash&quot;:&quot;<span style="padding: 0px; margin: 0px; font-size: 11px;">0x0000000000000000000000000000000000000000000000000000000000000000</span>&quot;,</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;extraData&quot;: &quot;SecBroBlock&quot;,</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&quot;gasLimit&quot;:&quot;0x0000ffff&quot;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">}</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">参数解释：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">
<table style="padding: 0px; margin: 0px;">
    <thead style="padding: 0px; margin: 0px;">
        <tr style="padding: 0px; margin: 0px;">
            <th style="padding: 0px; margin: 0px;">参数名称</th>
            <th align="center" style="padding: 0px; margin: 0px;">参数描述</th>
        </tr>
    </thead>
    <tbody style="padding: 0px; margin: 0px;">
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">mixhash</td>
            <td align="center" style="padding: 0px; margin: 0px;">与nonce配合用于挖矿，由上一个区块的一部分生成的hash。注意他和nonce的设置需要满足以太坊的Yellow paper, 4.3.4. Block Header Validity, (44)章节所描述的条件。</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">nonce</td>
            <td align="center" style="padding: 0px; margin: 0px;">nonce就是一个64位随机数，用于挖矿，注意他和mixhash的设置需要满足以太坊的Yellow paper, 4.3.4. Block Header Validity, (44)章节所描述的条件。</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">difficulty</td>
            <td align="center" style="padding: 0px; margin: 0px;">设置当前区块的难度，如果难度过大，cpu挖矿就很难，这里设置较小难度</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">alloc</td>
            <td align="center" style="padding: 0px; margin: 0px;">用来预置账号以及账号的以太币数量，因为私有链挖矿比较容易，所以我们不需要预置有币的账号，需要的时候自己创建即可以。</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">coinbase</td>
            <td align="center" style="padding: 0px; margin: 0px;">矿工的账号，随便填</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">timestamp</td>
            <td align="center" style="padding: 0px; margin: 0px;">设置创世块的时间戳</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">parentHash</td>
            <td align="center" style="padding: 0px; margin: 0px;">上一个区块的hash值，因为是创世块，所以这个值是0</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">extraData</td>
            <td align="center" style="padding: 0px; margin: 0px;">附加信息，随便填，可以填你的个性信息</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">gasLimit</td>
            <td align="center" style="padding: 0px; margin: 0px;">该值设置对GAS的消耗总量限制，用来限制区块能包含的交易信息总和，因为我们是私有链，所以填最大。</td>
        </tr>
    </tbody>
</table>
</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">启动私有链节点</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">启动私有节点所需参数</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">
<table style="padding: 0px; margin: 0px;">
    <thead style="padding: 0px; margin: 0px;">
        <tr style="padding: 0px; margin: 0px;">
            <th style="padding: 0px; margin: 0px;">参数名称</th>
            <th align="center" style="padding: 0px; margin: 0px;">参数描述</th>
        </tr>
    </thead>
    <tbody style="padding: 0px; margin: 0px;">
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">identity</td>
            <td align="center" style="padding: 0px; margin: 0px;">区块链的标示，随便填写，用于标示目前网络的名字</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">init</td>
            <td align="center" style="padding: 0px; margin: 0px;">指定创世块文件的位置，并创建初始块</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">datadir</td>
            <td align="center" style="padding: 0px; margin: 0px;">设置当前区块链网络数据存放的位置</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">port</td>
            <td align="center" style="padding: 0px; margin: 0px;">网络监听端口</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">rpc</td>
            <td align="center" style="padding: 0px; margin: 0px;">启动rpc通信，可以进行智能合约的部署和调试</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">rpcapi</td>
            <td align="center" style="padding: 0px; margin: 0px;">设置允许连接的rpc的客户端，一般为db,eth,net,web3</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">networkid</td>
            <td align="center" style="padding: 0px; margin: 0px;">设置当前区块链的网络ID，用于区分不同的网络，是一个数字</td>
        </tr>
        <tr style="padding: 0px; margin: 0px;">
            <td style="padding: 0px; margin: 0px;">console</td>
            <td align="center" style="padding: 0px; margin: 0px;">启动命令行模式，可以在Geth中执行命令</td>
        </tr>
    </tbody>
</table>
</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">启动</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">本人启动eth所在目录为：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">/home/zhuzs/eth</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">此目录下放置刚才配置好的创世块json文件：piccgenesis.json</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">因此直接执行如下命令：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">geth --identity &quot;secbro etherum&quot; --rpc --rpccorsdomain &quot;*&quot; --datadir &quot;/home/zhuzs/eth/chain&quot; --port &quot;30303&quot; --rpcapi &quot;db,eth,net,web3&quot; -- networkid 95518 console --dev&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">PS：根据自己的环境进行对应的替换。注意，最后添加了&ndash;dev，以开发模式启动。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">看到一下输出说明启动成功，并且是使用的私有链：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;"><img alt="" src="http://www.linuxdiyf.com/linux/uploads/allimg/161108/2-16110P95615317.png" style="padding: 0px; margin: 0px; border: none; width: 650px; height: 138px;" /></div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">随后就是相关的命令操作，在下一篇文章中进一步说明。</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-874-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 21:22</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-873-1.html</guid>
			<title>区块链开发（二）以太坊客户端操作命令</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">启动命令</span></p>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">重复上篇文章步骤，先将区块链客户端启动，命令如下：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">geth --identity &quot;secbro etherum&quot; --rpc --rpccorsdomain &quot;*&quot; --datadir &quot;/home/zhuzs/eth/chain&quot; --port &quot;30303&quot; --rpcapi &quot;db,eth,net,web3&quot; -- networkid 95518 console --dev</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">看到启动页面之后，新开启一个终端，并执行一下命令，并把日志输出到文本文件当中：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">geth --dev console 2&gt;&gt; file_to_log_output</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">这些需要注意的是，在启动客户端时添加了参数&ndash;dev，开发模式，这里直接使用dev参数来调用使用启动的服务，显示结果如下：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;"><img alt="" src="http://www.linuxdiyf.com/linux/uploads/allimg/161108/2-16110P9595E23.JPG" style="padding: 0px; margin: 0px; border: none; width: 650px;" /></div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">在这里可以执行具体的操作命令。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">查看账户</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">eth.accounts</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">创建用户：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">personal.newAccount(&quot;111111&quot;)</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">其中参数为此账户的密码。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">也可以先创建账户，然后输入密码：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">personal.newAccount()</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">查看区块数据</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">eth.blockNumber</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">启动挖矿</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">miner.start()</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">返回结果为true则启动成功，具体执行情况可查看日志。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">停止挖矿</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">miner.stop()</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">当在执行挖矿时日志会不停刷屏，不用管，只要命令输入全，执行即可停止挖矿。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">查看账户余额</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">其中参数为区块链地址</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">eth.getBalance(&quot;0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b&quot;)</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">转账</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">从账户<span style="padding: 0px; margin: 0px; font-size: 10px;">0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b</span>转账3个以太币到<span style="padding: 0px; margin: 0px; font-size: 10px;">0x587e57a516730381958f86703b1f8e970ff445d9</span>。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;"><span style="padding: 0px; margin: 0px; font-size: 10px;">eth.sendTransaction({from:&quot;0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b&quot;, to:&quot;0x587e57a516730381958f86703b1f8e970ff445d9&quot;,value:web3.toWei(3,&quot;ether&quot;)})</span></div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">当直接执行此方法时会抛出异常：</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">account is locked</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">at web3.js:3119:20</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">at web3.js:6023:15</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">at web3.js:4995:36</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">at &lt;anonymous&gt;:1:1</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">很明显，账户被锁。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">&nbsp;</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">解锁转出账户</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">其中第一个参数为转出账户，第二个参数为密码。也可以直填写第一个参数，然后通过命令行提示再输入密码。</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">personal.unlockAccount(&quot;0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b&quot;,&quot;111111&quot;)</div>
<div style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma; line-height: 25px;">解锁完成之后，即可执行转账操作。但此时查看时会发现接收账户依旧为原来数值。此时需要执行挖矿命令，才会把转账真正完成。</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-873-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 21:22</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-872-1.html</guid>
			<title>以太坊不同客户端的定义和用途</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">以太坊发布以后，有多个客户端，同时也支持多个平台，初学者往往被各种各样的客户端弄迷糊，本文进行了详细的总结。</span></p>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">以太坊客户端以语言进行分类，在github上分成了不同项目，源代码地址：https://github.com/ethereum/，虽然以太坊客户端众多，但是有两个共同特点：</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">1、同一语言的客户端在不同平台上的使用是完全相同的</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">2、不同语言的客户端（mist、geth、eth等等）之间在同一个平台（linux、windows或OSX）上共用一样的应用配置，同时其命令行可使用的参数也是一致。</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">下面就以github上的项目为分类说明各个客户端的用途和特点：</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;"><strong style="word-wrap: break-word;">一、go-ethereum项目</strong></div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">开发语言：go语言</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">客户端文件：Geth</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">界面：命令行</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">适用平台：windows、linux和OSX</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">功能和特点：该项目是使用最广泛的以太坊客户端，大部分节点都是运行的该客户端，教程和例子也最多，推荐使用，可用于挖矿，组建私有链，管理账号，部署智能合约等常用功能，不可以编译智能合约。</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;"><strong style="word-wrap: break-word;">二、webthree-umbrella项目</strong></div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">此项目包含3个客户端</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">开发语言：c++</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">客户端文件：AlethZero、Mix和Eth</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">使用平台：windows、linux和OSX</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">界面：图形化界面</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">功能和特点：该项目严格来说是cpp-ethereum 项目的一个shell，是以太坊基金会的前CTO，Gavin Wood主持编写的，所以人气也很高，易用性也很好。AlethZero是图形化的钱包客户端，对应的是Geth的功能，不过是全图形化的。但是随着后续以太坊基金会主推的图形化钱包Mist的推出，渐渐没落。Mix 是智能合约（以太坊称为DAPP）的开发IDE，可以支持智能合约（DAPP）的编写、调试，部署，全图形化界面，目前最主流的以太坊智能合约开发平台，非常方便，强烈推荐。Eth是C++编写的命令行客户端功能和Geth一样。</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;"><strong style="word-wrap: break-word;">三、Mist项目</strong></div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">开发语言：JavaScript</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">客户端文件：Mist（目前使用Ethereum-Wallet的名称）</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">使用平台：windows、linux和OSX</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">界面：图形化界面</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">功能和特点：该项目是以太坊基金会主推的项目，Mist定位不只是一个钱包，而是将来DAPP（智能合约的应用APP）市场，类似于苹果市场，在这里可以有你的账号，可以浏览、发布和买卖以太坊的DAPP应用。目前因为开发还不够全面，名称暂时显示为Ethereum-Wallet，作用也很简单，就是一个钱包的功能。强烈推荐，未来的主流客户端。</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;"><strong style="word-wrap: break-word;">四、solidity项目</strong></div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">开发语言：C++</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">客户端文件：solc</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">使用平台：windows、linux和OSX</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">界面：命令行界面</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">功能和特点：该项目是以太坊智能合约（DAPP）的编程语言，使用solc作为编译程序，该项目主要用于编译，严格来说是一个基本的编译平台，一般开发可用MIX替代。</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;"><strong style="word-wrap: break-word;">五、browser-solidity项目</strong></div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">开发语言：C++</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">客户端文件：浏览器中显示</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">使用平台：windows、linux和OSX</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">界面：浏览器界面</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">功能和特点：该项目是智能合约浏览器版本的开发环境，可以支持在浏览器中直接开发、调试和编译，对于初学者来说，可以快速上手，不需要安装，非常方便，直接访问地址使用：https://ethereum.github.io/browser-solidity/</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;"><strong style="word-wrap: break-word;">六、pyethereum项目和ethereumj项目</strong></div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">pyethereum项目是用python语言编写的以太坊客户端，ethereumj项目是用JAVA语言编写的以太坊客户端，只是语言不同，和前面GO语言编写的客户端Geth的功能完全相同。</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;"><strong style="word-wrap: break-word;">七、etheminer项目</strong></div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">开发语言：C++</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">客户端文件：ethminer</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">使用平台：windows、linux和OSX</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">界面：命令行</div>
<div style="word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(74, 74, 74); font-family: 'Microsoft Yahei', 'Hiragino Sans GB', Helvetica, 'Helvetica Neue', 微软雅黑, Tahoma, Arial, sans-serif; font-size: 16px; line-height: 30px;">功能和特点：该项目是cpp-ethereum项目的一部分，用于和Geth配合进行GPU挖矿，比CPU挖矿效率高100多倍，也可以用于矿池挖矿。</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-872-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 21:18</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-871-1.html</guid>
			<title>以太坊开发快速上手指南 + 开发相关文章</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;</p>
<h2 id="以太坊快速上手指南" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">以太坊快速上手指南</h2>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">在正式开始前，首先推荐过下这篇文章&nbsp;<a href="http://ethfans.org/topics/102" rel="nofollow" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">http://ethfans.org/topics/102</a><br style="box-sizing: inherit;" />
如果你暂时不想了解区块链的技术细节，比如什么工作量证明，公钥加密系统什么的，可以先直接跳过。但还是强烈建议在你对整个开发流程有了点感觉后，把这部分知识补充起来。</p>
<h3 id="区块链部分" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">区块链部分</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;"><a href="http://teahour.fm/2015/12/27/talk-with-jan-about-bitcoin-and-blockchain.html" rel="nofollow" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">http://teahour.fm/2015/12/27/talk-with-jan-about-bitcoin-and-blockchain.html</a></p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;"><a href="http://teahour.fm/2016/01/19/talk-with-jan-about-ehtereum.html" rel="nofollow" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">http://teahour.fm/2016/01/19/talk-with-jan-about-ehtereum.html</a>&nbsp;（文字稿：<a href="http://ethfans.org/posts/talk-with-jan-about-ehtereum" rel="nofollow" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">http://ethfans.org/posts/talk-with-jan-about-ehtereum</a>）</p>
<h3 id="编写智能合约" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">编写智能合约</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">Ethereum提供两种智能合约编程语言<a href="https://solidity.readthedocs.org/en/latest/" title="Solidity Document" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Solidity</a>和<a href="https://github.com/ethereum/wiki/wiki/Serpent" title="Serpent Document" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Serpent</a>，<a href="https://solidity.readthedocs.org/en/latest/" title="Solidity Document" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Solidity</a>的语法类似于JavaScript，而<a href="https://github.com/ethereum/wiki/wiki/Serpent" title="Serpent Document" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Serpent</a>的语法接近于Python。但也仅仅是语法有点类似，事实上有着巨大的差别，学习时不能简单的代入理解。如果你对编程语言没有偏好，请选择Solidity，也是默认的智能合约编程语言。Solidity文档中文版（正在翻译中，欢迎开发者参与翻译）：<a href="http://ethfans.org/posts/solidity-content" rel="nofollow" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">http://ethfans.org/posts/solidity-content</a>&nbsp;。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">如果不想搭建完整的ethereum开发环境，只是想了解下<a href="https://solidity.readthedocs.org/en/latest/" title="Solidity Document" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Solidity</a>，可以看下这个项目：<a href="https://github.com/chriseth/browser-solidity" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Browser-Solidity</a></p>
<h3 id="常用辅助工具和开发环境" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">常用辅助工具和开发环境</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">以太坊的开发生态正在日益完善，相比刚发布时的裸写，现在已经有很多开发工具供选择了。</p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px; line-height: 25.5px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;"><a href="https://github.com/ConsenSys/truffle" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Truffle</a>:&nbsp;<a href="https://consensys.net/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">ConsenSys</a>团队的开发工具</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;"><a href="https://github.com/iurimatias/embark-framework" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Embark</a>: 最早的一个开发工具</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;"><a href="https://github.com/NexusDevelopment/dapple" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Dapple</a>: [Nexus Development]的开发工具，他们也是<a href="http://daibond.info/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">DAI/Maker</a>项目背后的开发团队</li>
</ul>
<h3 id="以太坊本地私有链开发环境搭建教程（中文） ： http://ethfans.org/posts/ethereum-private-network-bootstrap" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">以太坊本地私有链开发环境搭建教程（中文） ：&nbsp;<a href="http://ethfans.org/posts/ethereum-private-network-bootstrap" rel="nofollow" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">http://ethfans.org/posts/ethereum-private-network-bootstrap</a></h3>
<h3 id="Đapp" style="box-sizing: inherit; margin: 0px 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.17rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">Đapp</h3>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">通常你都是在写一个面向最终用户的应用，这时你需要一个界面。以太坊的开发者通常使用Web App + Smart Contract的方式来搭建这样的应用，并称之为Đapp(Decentralised Application)。在这里，智能合约部分的代码就相当于BS架构中的服务器代码，而Web部分则相当于前端代码。Web部分可以使用你熟悉的的HTML + JavaScript + CSS 来完成，然后通过JSONRPC的方法使用以太坊客户端提供的API接口，来操作你部署在区块链上的智能合约，这里区块链就相当于你租用的一台云服务器，所以有时候我们可以把以太坊的区块链理解为全球共享的一台World Computer。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">Đapp最为关键的就是如何进行JSONRPC调用，以太坊官方提供了一个工具:&nbsp;<a href="https://github.com/ethereum/web3.js" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Web3.js</a>。如果你开发Đapp, 就必然需要使用它。</p>
<p style="box-sizing: inherit; margin-bottom: 0px; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">如何搭建一个测试网络并运行一个简单的 dapp&nbsp;<a href="http://ethfans.org/topics/85" rel="nofollow" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">http://ethfans.org/topics/85</a></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-871-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 20:04</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-870-1.html</guid>
			<title>以太坊本地私有链开发环境搭建</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="line-height: 1.7em; color: rgb(51, 51, 51); font-family: Georgia, 'Times New Roman', 'Rhythm Cursive', serif; font-size: 16px;">ethereum-bootstrap是我建立的一个github项目，目的是帮助刚接触以太坊的同学快速的搭建起自己的本地开发环境，体验智能合约的开发。阅读本文需要有基本的编程知识。项目地址:</span><span style="line-height: 1.7em; color: rgb(51, 51, 51); font-family: Georgia, 'Times New Roman', 'Rhythm Cursive', serif; font-size: 16px;">&nbsp;</span><a href="https://github.com/janx/ethereum-bootstrap" rel="nofollow" target="_blank" style="font-size: 16px; box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">https://github.com/janx/ethereum-bootstrap</a></p>
<h2 id="Ethereum Bootstrap" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">Ethereum Bootstrap</h2>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">通过本文所述方法和项目中的脚本，我们可以快速的搭建好自己的私链进行开发测试。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">仓库中包含的工具有：</p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">一个测试账户导入脚本，在首次部署时将五个测试账户私钥导入以太坊节点。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">一个genesis.json配置文件，为对应的五个测试账户提供初始资金（以太币），方便开发测试。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">一个快速启动私有链节点并进入交互模式的脚本。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">一个合约样例：<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contracts/Token.sol</code>。这是一个使用合约语言<a href="http://solidity.readthedocs.org/en/latest/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">Solidity</a>编写的智能合约。Token合约的功能是发行一种token（可以理解为货币，积分等等），只有合约的创建者有发行权，token的拥有者有使用权，并且可以自由转账。</li>
</ul>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><strong style="box-sizing: inherit;">测试账户私钥是放在Github上的公开数据，千万不要用于正式环境中或者公有链上。如果在测试环境之外的地方使用这些私钥，你的资金将会被窃取！</strong></p>
<h2 id="准备" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">准备</h2>
<ol style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">在本地安装好<a href="https://github.com/ethereum/go-ethereum" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">go-ethereum</a>和<a href="http://solidity.readthedocs.org/en/latest/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">solc</a>, 可以执行<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">geth</code>和<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">solc</code>命令。如果操作系统是ubuntu, 安装官方的ethereum安装包即可。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">将本仓库通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">git clone</code>命令下载到本地。</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">安装<a href="http://expect.sourceforge.net/" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">expect</a>，工具脚本用它来自动化一些过程。例如在ubuntu上:&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">sudo apt-get install expect</code></li>
</ol>
<h2 id="启动geth" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">启动geth</h2>
<ol style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px; line-height: 27.2px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">进入本仓库目录:&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">cd ethereum-bootstrap</code></li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">导入测试账户私钥:&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">./bin/import_keys.sh</code></li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">启动私有链节点:&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">./bin/private_blockchain.sh</code>. 启动成功后可以看到类似如下输出:&nbsp;<img src="http://ethfans.org/uploads/photo/2016/513135073f6ae5cd6afcef29ae5b8e8e.png" alt="" style="box-sizing: inherit; border: 0px; max-width: 100%; height: auto;" /></li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">此时以太坊交互式控制台已经启动，我们可以开始测试和开发了。</li>
</ol>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">注意：工具脚本假设你的geth安装在默认位置, 可以直接通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">geth</code>执行。如果<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">geth</code>命令安装在非标准的位置，可以设置<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">GETH</code>环境变量指定geth可执行文件的路径。例如:</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">GETH=/some/weird/dir/geth ./bin/import_keys.sh</code></p>
<h2 id="使用以太坊控制台编译和部署智能合约" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">使用以太坊控制台编译和部署智能合约</h2>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">在<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contracts</code>目录下有一个智能合约样例文件<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">Token.sol</code>, 通过Solidity语言实现了基本的代币功能, 合约持有者可以发行代币, 使用者可以互相转账.</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">我们可以使用以太坊控制台来编译部署这个合约．以太坊控制台是最基本的工具，使用会比较繁琐．社区也提供了其他更加方便的部署工具，此处不做讨论．</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">第一步，我们先把合约代码压缩为一行．新建一个ssh session, 切换到geth用户环境<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">su - geth</code>, 然后输入：<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">cat contracts/Token.sol | tr '\n' ' '</code>.</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">切换到以太坊控制台，把合约代码保存为一个变量:</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">tokenSource</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="s1" style="box-sizing: inherit; color: rgb(208, 16, 64);">'contract Token {     address issuer;     mapping (address =&gt; uint) balances;      event Issue(address account, uint amount);     event Transfer(address from, address to, uint amount);      function Token() {         issuer = msg.sender;     }      function issue(address account, uint amount) {         if (msg.sender != issuer) throw;         balances[account] += amount;     }      function transfer(address to, uint amount) {         if (balances[msg.sender] &lt; amount) throw;          balances[msg.sender] -= amount;         balances[to] += amount;          Transfer(msg.sender, to, amount);     }      function getBalance(address account) constant returns (uint) {         return balances[account];     } }'</span><span class="p" style="box-sizing: inherit;">;</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">然后编译合约代码：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">tokenCompiled</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">compile</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">solidity</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">tokenSource</span><span class="p" style="box-sizing: inherit;">);</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">tokenCompiled.Token.code</code>可以看到编译好的二进制代码，通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">tokenCompiled.Token.info.abiDefinition</code>可以看到合约的<a href="https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">ABI</a>．</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">接下来我们要把编译好的合约部署到网络上去．</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">首先我们用ABI来创建一个javascript环境中的合约对象：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">contract</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">contract</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">tokenCompiled</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">Token</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">info</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">abiDefinition</span><span class="p" style="box-sizing: inherit;">);</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">我们通过合约对象来部署合约：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">initializer</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="p" style="box-sizing: inherit;">{</span><span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">from</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">web3</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">eth</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">accounts</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: inherit;">],</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">data</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nx" style="box-sizing: inherit;">tokenCompiled</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">Token</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">code</span><span class="p" style="box-sizing: inherit;">,</span> <span class="na" style="box-sizing: inherit; color: rgb(0, 128, 128);">gas</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">300000</span><span class="p" style="box-sizing: inherit;">};</span>  <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">callback</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">function</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">e</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nx" style="box-sizing: inherit;">contract</span><span class="p" style="box-sizing: inherit;">){</span>     <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">if</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">!</span><span class="nx" style="box-sizing: inherit;">e</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>       <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">if</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">!</span><span class="nx" style="box-sizing: inherit;">contract</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">address</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>         <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Contract transaction send: TransactionHash: &quot;</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">+</span> <span class="nx" style="box-sizing: inherit;">contract</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">transactionHash</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">+</span> <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot; waiting to be mined...&quot;</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="p" style="box-sizing: inherit;">}</span> <span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">else</span> <span class="p" style="box-sizing: inherit;">{</span>         <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;Contract mined!&quot;</span><span class="p" style="box-sizing: inherit;">);</span>         <span class="nx" style="box-sizing: inherit;">console</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">log</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">contract</span><span class="p" style="box-sizing: inherit;">);</span>       <span class="p" style="box-sizing: inherit;">}</span>     <span class="p" style="box-sizing: inherit;">}</span> <span class="p" style="box-sizing: inherit;">};</span>  <span class="kd" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">var</span> <span class="nx" style="box-sizing: inherit;">token</span> <span class="o" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">=</span> <span class="nx" style="box-sizing: inherit;">contract</span><span class="p" style="box-sizing: inherit;">.</span><span class="k" style="box-sizing: inherit; color: rgb(0, 0, 0); font-weight: bold;">new</span><span class="p" style="box-sizing: inherit;">(</span><span class="nx" style="box-sizing: inherit;">initializer</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nx" style="box-sizing: inherit;">callback</span><span class="p" style="box-sizing: inherit;">);</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contract.new</code>方法的第一个参数设置了这个新合约的创建者地址<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">from</code>, 这个新合约的代码<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">data</code>, 和用于创建新合约的费用<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">gas</code>．<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">gas</code>是一个估计值，只要比所需要的gas多就可以，合约创建完成后剩下的gas会退还给合约创建者．</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contract.new</code>方法的第二个参数设置了一个回调函数，可以告诉我们部署是否成功．</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">contract.new</code>执行时会提示输入钱包密码．执行成功后，我们的合约Token就已经广播到网络上了．此时只要等待矿工把我们的合约打包保存到以太坊区块链上，部署就完成了．</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">在公有链上，矿工打包平均需要15秒，在私有链上，我们需要自己来做这件事情．首先开启挖矿：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">miner</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">start</span><span class="p" style="box-sizing: inherit;">(</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">)</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">此时需要等待一段时间，以太坊节点会生成挖矿必须的数据，这些数据都会放到内存里面．在数据生成好之后，挖矿就会开始，稍后就能在控制台输出中看到类似：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">:hammer:Mined block</code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">的信息，这说明挖到了一个块，合约已经部署到以太坊网络上了！此时我们可以把挖矿关闭：</p>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">miner</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">stop</span><span class="p" style="box-sizing: inherit;">(</span><span class="mi" style="box-sizing: inherit; color: rgb(0, 153, 153);">1</span><span class="p" style="box-sizing: inherit;">)</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">接下来我们就可以调用合约了．先通过<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">token.address</code>获得合约部署到的地址, 以后新建合约对象时可以使用．这里我们直接使用原来的contract对象：</p>
<pre class="highlight plaintext" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 27.2px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">// 本地钱包的第一个地址所持有的token数量 &gt; token.getBalance(web3.eth.accounts[0]) 0  // 发行100个token给本地钱包的第一个地址 &gt; token.issue.sendTransaction(web3.eth.accounts[0], 100, {from: web3.eth.accounts[0]}); I1221 11:48:30.512296   11155 xeth.go:1055] Tx(0xc0712460a826bfea67d58a30f584e4bebdbb6138e7e6bc1dbd6880d2fce3a8ef) to: 0x37dc85ae239ec39556ae7cc35a129698152afe3c &quot;0xc0712460a826bfea67d58a30f584e4bebdbb6138e7e6bc1dbd6880d2fce3a8ef&quot;  // 发行token是一个transaction, 因此需要挖矿使之生效 &gt; miner.start(1) :hammer:Mined block &gt; miner.stop(1)  // 再次查询本地钱包第一个地址的token数量 &gt; token.getBalance(web3.eth.accounts[0]) 100  // 从第一个地址转30个token给本地钱包的第二个地址 &gt; token.transfer.sendTransaction(web3.eth.accounts[1], 30, {from: web3.eth.accounts[0]}) I1221 11:53:31.852541   11155 xeth.go:1055] Tx(0x1d209cef921dea5592d8604ac0da680348987b131235943e372f8df35fd43d1b) to: 0x37dc85ae239ec39556ae7cc35a129698152afe3c &quot;0x1d209cef921dea5592d8604ac0da680348987b131235943e372f8df35fd43d1b&quot; &gt; miner.start(1) &gt; miner.stop(2) &gt; token.getBalance(web3.eth.accounts[0]) 70 &gt; token.getBalance(web3.eth.accounts[1]) 30</code></pre>
<h2 id="其他" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1.5rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">其他</h2>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">私有链的所有数据都会放在仓库根目录下的<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 13.6px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">data</code>目录中，删除这个目录可以清除所有数据，重新启动新环境。</p>
<p style="box-sizing: inherit; margin-bottom: 0px; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">做完这些之后你应该对在以太坊私有链上进行开发有了一个大概的了解吧，如果还想学习更多知识，一可以看一看上面执行的脚本代码，到底干了些什么，用了哪些命令行参数，二可以阅读正在ethfans上更新的<a href="http://ethfans.org/topics/174" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">solidity文档中文版</a>。</p>
<p style="box-sizing: inherit; margin-bottom: 0px; line-height: 27.2px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 16px;">&nbsp;</p>
<p style="box-sizing: inherit; margin-bottom: 0px;"><font color="#333333" face="Source Sans Pro, Helvetica Neue, Helvetica, Arial, Rhythm Heiti, sans-serif"><span style="font-size: 16px; line-height: 27.2px;"><a href="http://ethfans.org/posts/ethereum-private-network-bootstrap">http://ethfans.org/posts/ethereum-private-network-bootstrap</a></span></font></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-870-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 20:01</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-869-1.html</guid>
			<title>如何搭建一个测试网络并运行一个简单的 dapp</title>
			<author>admin</author>
			<description><![CDATA[<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">对于开发者而言，在一个新平台上开发应用之前，一个可控的测试环境是必不可少的。<br style="box-sizing: inherit;" />
对于普通用户而言，在正式的链上开始使用钱包转账，在etherex挂单等等严肃操作之前，先在一个demo程序上熟悉下功能，也能减少出错概率。</p>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">以太坊作为一个&ldquo;去中心化的应用平台&rdquo;，也确实给搭建测试网络提供了很多便利。以下我们就一步一步的介绍如何搭建一个测试链，并在测试链上运行ethereum.org上的hello world程序。</p>
<h4 id="准备工作" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">准备工作</h4>
<ol style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px; line-height: 25.5px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">安装geth</li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">如果你准备连接到我在阿里云上的testnet, 下载这个<a href="http://ethfans.org/uploads/example_genesis.json" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">创世块</a></li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">如果你要搭建自己的testnet，可以参照<a href="https://github.com/ethereum/go-ethereum/wiki/Connecting-to-the-network#custom-networks" target="_blank" style="box-sizing: inherit; line-height: 1em; text-decoration: none; transition: all 0.5s; color: rgb(112, 137, 169); font-family: 'Rhythm Italic Serif', 'Rhythm Heiti', sans-serif; word-break: break-all; background-color: transparent;">这里</a>的格式创建创世块</li>
</ol>
<h4 id="开始" style="box-sizing: inherit; margin: 1.2em 0px 0.4em; padding: 0px; color: rgb(34, 34, 34); font-weight: normal; line-height: 1.3em; font-size: 1rem; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif;">开始</h4>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px; line-height: 25.5px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">首先打开你的终端输入如下命令启动geth</li>
</ul>
<pre class="highlight shell" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 15px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 25.5px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 12.75px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;">geth --bootnodes <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;enode://7cc0c2e8abd944d6bee8966fc21b0597de27ef912614ff1b7b4f2c51b7d72078d05038435686f8821aa7ce6918a6065192368bb05cd50a908ed2f8958dfa7197@115.29.32.87:30303&quot;</span> --datadir <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;YOURTESTNETDATADIR&quot;</span> --genesis <span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;EXAMPLEGENESIS.json&quot;</span>  --networkid 12345 --nodiscover console</code></pre>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px; line-height: 25.5px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">
    <p style="box-sizing: inherit; margin-bottom: 0px; line-height: 1.7em;">当屏幕上出现这样的文字后&nbsp;<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 12.75px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">modules: admin:1.0 db:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 shh:1.0 txpool:1.0 web3:1.0</code>&nbsp;你就进入了以太坊的命令行控制界面</p>
    </li>
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">
    <p style="box-sizing: inherit; margin-bottom: 0px; line-height: 1.7em;">在以太坊的命令行界面输入如下命令创建一个新的账户</p>
    </li>
</ul>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 15px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 25.5px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 12.75px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">personal</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">newAccount</span><span class="p" style="box-sizing: inherit;">(</span><span class="s1" style="box-sizing: inherit; color: rgb(208, 16, 64);">'ethfans'</span><span class="p" style="box-sizing: inherit;">)</span></code></pre>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px; line-height: 25.5px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">加入阿里云上我搭建的testnet node（如果你搭建一个人的testnet，不需要这一步）</li>
</ul>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 15px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 25.5px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 12.75px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">admin</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">addPeer</span><span class="p" style="box-sizing: inherit;">(</span><span class="s2" style="box-sizing: inherit; color: rgb(208, 16, 64);">&quot;enode://7cc0c2e8abd944d6bee8966fc21b0597de27ef912614ff1b7b4f2c51b7d72078d05038435686f8821aa7ce6918a6065192368bb05cd50a908ed2f8958dfa7197@115.29.32.87:30303&quot;</span><span class="p" style="box-sizing: inherit;">)</span></code></pre>
<p style="box-sizing: inherit; margin-bottom: 1em; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">然后输入<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 12.75px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">admin.peers</code>检查是否已添加成功远程节点， 添加失败的话会返回<code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 12.75px; margin: 0px; padding: 2px 4px; border-radius: 2px; border: 1px solid rgb(224, 224, 224); white-space: pre-wrap;">null</code></p>
<ul style="box-sizing: inherit; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-left: 2em; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px; line-height: 25.5px;">
    <li style="box-sizing: inherit; margin: 0px; padding: 0px; line-height: 1.7em;">开始挖矿（第一次挖矿需要生成一个2G的DAG文件，耗时10分钟左右，具体时长取决于电脑性能）</li>
</ul>
<pre class="highlight javascript" style="box-sizing: inherit; overflow: auto; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 15px; margin-top: 0px; margin-bottom: 1em; padding: 1em; border: 1px solid rgb(224, 224, 224); word-wrap: normal; color: rgb(51, 51, 51); line-height: 25.5px; background-color: rgb(247, 247, 247);"><code style="box-sizing: inherit; font-family: Menlo, Courier, monospace, monospace, sans-serif; font-size: 12.75px; margin: 0px; padding: 0px; border-radius: 2px; border: none; white-space: pre-wrap; word-break: break-all; background-color: transparent;"><span class="nx" style="box-sizing: inherit;">miner</span><span class="p" style="box-sizing: inherit;">.</span><span class="nx" style="box-sizing: inherit;">start</span><span class="p" style="box-sizing: inherit;">()</span></code></pre>
<hr style="box-sizing: content-box; height: 1px; margin: 1em 0px; padding: 0px; border-top-width: 0px; border-right-width: 0px; border-left-width: 0px; border-bottom-style: dashed; border-bottom-color: rgb(224, 224, 224); color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px; line-height: 25.5px;" />
<p style="box-sizing: inherit; margin-bottom: 0px; line-height: 25.5px; color: rgb(51, 51, 51); font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 'Rhythm Heiti', sans-serif; font-size: 15px;">待续</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-869-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 20:00</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-868-1.html</guid>
			<title>etherenum钱包安装</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;etherenum钱包安装</p>
<div>https://github.com/ethereum/go-ethereum/archive/v1.5.4.tar.gz</div>
<div>&nbsp;</div>
<div>&nbsp;geth</div>
<div>geth -datadir &quot;D:ethereum&quot;</div>
<div>geth account new</div>
<div>geth account list</div>
<div>geth wallet import</div>
<div>geth console</div>
<div>&nbsp;</div>
<div>get attach</div>
<div>net.listening</div>
<div>net.peerCount</div>
<div>admin.peers</div>
<div>admin.nodeInfo</div>
<div>eth.blockNumber</div>
<div>eth.accounts</div>
<div>&nbsp;</div>
<div>创建用户：</div>
<div>personal.newAccount(&quot;111111&quot;)</div>
<div>其中参数为此账户的密码。</div>
<div>也可以先创建账户，然后输入密码：</div>
<div>personal.newAccount()</div>
<div>&nbsp;</div>
<div>查看账户余额</div>
<div>其中参数为区块链地址</div>
<div>eth.getBalance(&quot;0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b&quot;)</div>
<div>eth.getBalance(eth.accounts[0])</div>
<div>&nbsp;</div>
<div>personal.unlockAccount(eth.accounts[0], '123456')</div>
<div>&nbsp;</div>
<div>启动挖矿</div>
<div>miner.start()</div>
<div>miner.stop()</div>
<div>&nbsp;</div>
<div>首先，输入geth console，回车。</div>
<div>方法一：</div>
<div>然后，解锁账户。输入personal.unlockAccount(addr, passwd, duration)，addr是你的地址，passwd是账户密码，duration是账户处于解锁状态的时间，例如300表示在300秒内无需再次解锁。建议在记事本中写完此命令，复制到geth中。成功解锁账户，界面会返回 true。</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>testrpc. 用geth可以创建一个测试网络，另一种更快的创建测试网络的方法是使用testrpc. Testrpc可以在启动时帮你创建一堆存有资金的测试账户。它的运行速度也更快因此更适合开发和测试。你可以从testrpc起步，然后随着合约慢慢成型，转移到geth创建的测试网络上 - 启动方法很简单，只需要指定一个networkid：geth --networkid &quot;12345&quot;。这里是testrpc的代码仓库，下文我们还会再讲到它。</div>
<div>&nbsp;</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-868-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-50-1.html">区块链</category>
			<pubDate>2016-12-13 19:59</pubDate>
		</item>
	</channel>
</rss>
