账号创建完成之后,账号余额是0,但是部署合约是需要消耗GAS的,因此需要获取一定的以太币才能够继续本次实现。在测试网中获取以太币可以通过挖矿的方式,在开发菜单中可以选择打开挖矿模式,但是这需要将Syn Mode模式修改为Full,这意味着需要将测试网的全部区块数据同步下来才可以进行挖矿,这些数据非常大且同步缓慢,因此建议采用第2种方案:到以太坊基金会申请以太币,读者可以自行搜索“获取测试网以太坊币”,会有相关的网址获取以太币,一般需要输入读者自己的测试环境以太坊账号。
& nbsp; After the creation of the account, the account balance is zero, but the deployment contract is required to consume the GAS, and therefore a certain amount of TT will need to be obtained in order to continue the exercise. In the test network, it is possible to open the mining mode in the development menu by acquiring TT$ for mining, but this requires changing the SynMode model to Full, which means that mining can be done only by synchronizing all of the test network data, which is very large and slow, and it is therefore recommended that option 2: to apply for TT$ in the Etherm Foundation, readers can search for TT$ on their own initiative. There will be a relevant web site for TT$, which usually needs to be entered into the reader's own test environment for TT$.
(1)本节使用的代码案例需要2个以上的以太坊账号,请读者申请创建2个账号并分别申请测试用的ETH代币。成功创建账号并获取以太币之后,就可以开始部署智能合约的操作了,如图2.13所示,选择 COTRACT->DEPLOY NEW CONTRACT。
(1) The code case used in this section requires two or more eBay accounts. Readers are invited to apply for the creation of two accounts and for the testing of the ETH tokens separately. Once the account numbers have been successfully created and obtained, the operation of the smart contract can be started, as shown in Figure 2.13, selecting Contractor-> DEPLY NEW CONTRACT.
图2.13 智能合约tab页面
Figure 2.13 Smart Contract Tab Page
(2)将上一章用的Coin合约代码复制粘贴到图2.14中3的区域,其中1表示账号用于部署该合约的账号,对应于Coin构造函数的msg.sender这个内容。区域2表示给当前的智能合约转账多少,单位是以太币的个数。4表示该合约代码存在编译错误,需要修改。
(2) Reproduces the Coin contract code used in the previous chapter to the area in figure 2.14, which indicates the account number used to deploy the contract, corresponding to the msg.sender part of the Coin construction function. Area 2 indicates the amount of money transferred to the current smart contract in the currency. 4 indicates a compilation error in the contract code that needs to be modified.
图2.14智能合约代码输入
Figure 2.14 Smart contract code entry
(3)稍作修改之后,代码编译通过。在代码的右侧,是一个下拉选项,选项中有智能合约的名称列表,此示例中仅有Coin一个智能合约,选中此合约,在合约代码的下方有GAS费用调节的滑块和DEPLOY按钮。GAS费用前面讲到过,付出越高的GAS费用,被矿工选中打包成区块的概率也越高,如图2.15所示,此示例中我们选中默认GAS数量,然后点击DEPLOY按钮。
(3) The code has been compiled with minor modifications. On the right side of the code, there is a drop-down option with a list of names for smart contracts, in which only Coin has a smart contract, and this contract has been selected with a GAS cost-adjusted slider and a DEPLOY button at the bottom of the code. As already mentioned above, the higher the cost of GAS, and the higher the probability of being packaged into blocks selected by the miners, as shown in figure 2.15, we select the default GAS number, and then click on the DEPLOY button.
图2.15选择智能合约名称并修改GAS费用
Figure 2.15 Select the name of the smart contract and change the GAS cost
(4)点击部署合约之后,以太坊钱包会弹出交易转账密码输入的对话框,此密码即为秘钥的加密密码,通过输入密码,以太坊钱包动态的解密私钥,通过私钥对交易进行签名,然后广播到以太坊网络中,该交易会加入到交易池中并显示为pending状态。矿工会选择该交易并将智能合约运行来修改以太坊状态机的状态。修改成功之后,将产生的新状态以及交易收据、永久存储数据、余额等信息写入到以太坊,并将所有数据打包进新的区块。
(4) After clicking on the deployment contract, the trade transfer password entered into the dialogue box is ejected with the Taiwan Wallet. The password is the crypto key, signed by entering the password, decrypted private keys to the cell wallet dynamics, and then broadcast to the Ethernet, where the transaction will be added to the trading pool and shown as pending status. The mining union selects the transaction and operates the smart contract to modify the state of the machine in the taupuleta. After the changes have been made, the new state and the information generated by the transaction receipt, permanent storage data, balances etc. will be written into Etheria, and all data will be packaged into a new block.
(5)正确输入密码并SEND TRASACTION之后,以太坊钱包会进入等待以太坊网络矿机打包的过程中,图2.16就是正在等待交易被打包,该交易是一个Create Contract的操作。交易被成功打包到新的区块之后,会生成关于该交易的很多索引信息,如图2.17所示。
(5) After correctly entering the password and SEND TRANSACTION, Ether’s wallet will enter the process of waiting for the Ethernet miner to pack, figure 2.16 is waiting for the transaction to be packaged, which is a Create Contracting operation. When the transaction is successfully packaged into a new block, much of the index information about the transaction will be generated, as shown in figure 2.17.
图2.16输入密码,支付费用以便部署智能合约
Figure 2.16 Enter the password and pay for the deployment of the smart contract
图2.17交易等待打包的状态提示
Figure 2.17 Conditional reminder for transactions awaiting packing
(6)图2.18中,1是交易的hash值,点击该链接可以打开区块链浏览器,查看关于该交易的更多详细信息;2是区块打包的时间;3表示该交易设计的转账金额,本示例只是创建合约,并没有转移以太币;4是发起改交易的以太坊账户,点击该选项可以打开区块链浏览器,查看关于该账户的所有交易记录,任何有人都可以查到这些信息,因此区块链是透明公开的;5表示该交易的目的地址,创建智能合约时改地址是空;6、7、8表示执行该交易消耗的以太坊代币数量、GAS数量和GAS的价格,这些是该交易的交易手续费,是给以太坊矿工的激励,当然目前使用的是以太坊测试网,该网络的以太币并没有兑换价值;9表示该交易所在的区块高度,点击链接可以进入区块链浏览器查看该区块的其它信息。
(6) Figure 2.18 shows the hash value of the transaction and clicks on the link to open the block chain browser for more detailed information about the transaction; 2 is the time when the block is packed; 3 indicates the transfer amount of the transaction design, which is only the creation of the contract and is not transferred in TT; 4 is the Ether account that initiated the transaction and clickes on the option to open the block chain browser for all transactions relating to the account, which is accessible to anyone and therefore transparent; 5 indicates the intended address of the transaction and the change of address when creating the smart contract is empty; 6, 7 and 8 indicate the amount of currency consumed by the transaction, the number of GAS and the price of the GAS, which are transaction fees, incentives for the miners in the area, of course, are currently used to test the network, which has no currency exchange value; 9 indicates that the exchange is located at the height of the block and that the link can be accessed into the row browser to view other information on the block.
图2.18创建智能合约产生的交易信息
Figure 2.18 Transaction information generated by the creation of smart contracts
(7)如图2.19所示,点击交易hash值之后浏览器打开的区块链浏览器信息,读者可以自行点击其它信息。该浏览器是第三方开发,与区块链钱包类似,任何人和机构都可以开发钱包和浏览器,以太坊的数据是无主的,去中心化的,任何人都可以开发软件来访问以太坊区块链上的交易数据,这就是区块链公开透明的魅力。同时因为加密学的应用,即使所有数据对所有人公开,代码和规则也公开,也无法通过篡改数据的方式来破坏区块链网络,或者通过作恶的方式来获取区块链上的数字货币,这就为区块链的创新应用提供了技术支持。
(7) As shown in figure 2.19, a block-chain browser opened by the browser after clicking on the trade hash value allows readers to click on other information on their own. The browser is developed by a third party and is similar to the block-chain wallet. Any person and institution can develop wallets and browsers, in which there is no ownership, decentralized data, and anyone can develop software to access transaction data in the section chain, which is the open and transparent charm of the block chain. Also, because encryption applications, even if all data are available to everyone, codes and rules are open, cannot destroy the block-chain network by tampering with data, or by corrupting to obtain digital currency in the block-chain, which provides technical support for innovative application of the block-chain.
图2.19 以太坊区块链浏览器
Figure 2.19 Ether Block Chain Browser
(8)如图2.20所示,当交易打包完成之后,回到CONTRACTS页下面,可以看到刚刚创建的智能合约显示在了界面中。点击该智能合约,进入下一环节,调试智能合约。
(8) As shown in figure 2.20, when the transaction is packaged, then back below the CONTRACTS page, you can see that the intelligence contract that has just been created is displayed in the interface. Click on the smart contract, enter the next segment, debugging the smart contract.
图2.20 合约创建成功之后的界面
Figure 2.20 Interface after contract creation
2020区块链各种应用都上马了,跟我一起学《区块链DAPP开发入门、代码实现、场景应用》吧。
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论