《区块链DAPP开发入门、代码实现、场景应用》笔记4

资讯 2024-07-10 阅读:77 评论:0
  账号创建完成之后,账号余额是0,但是部署合约是需要消耗GAS的,因此需要获取一定的以太币才能够继续本次实现。在测试网中获取以太币可以通过挖矿的方式,在开发菜单中可以选择打开挖矿模式,但是这需要将Syn Mode模式修改为Fu...
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

  账号创建完成之后,账号余额是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开发入门、代码实现、场景应用》吧。



美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
热门文章
  • 支付領域投下震撼彈!美國數位銀行Chime疑與GuardPay 神盾支付合作!

    支付領域投下震撼彈!美國數位銀行Chime疑與GuardPay 神盾支付合作!
    2020年,新冠肺炎(COVID-19)疫情加速數位貨幣進展。例如:2019年4月,國際清算銀行(BIS)的調查顯示,在全球66家中央銀行中,沒有一家計畫發行跨境支付的數位貨幣。惟到了2020年10月,BIS支付委員會主席康利夫(Jon Cunliffe)指出,肺炎疫情拉高民眾對無現金支付的需求,迫使各國加快數位貨幣的研發進程日本與韓國於2021年進入數位貨幣試驗階段。直到2019年12月,美國聯邦準備理事會(Fed)都尚無數位貨幣規劃,惟到了2020年2月,Fed已開始研擬...
  • 区块链:交易系统开发指南

    区块链:交易系统开发指南
    播报编辑《区块链:交易系统开发指南》使用通俗易懂的语言,从技术的角度详细介绍了区块链交易系统应有的功能架构及工作原理,让人们能够张开双臂轻松地拥抱区块链技术,享受区块链交易系统带来的惊喜与成就感。《区块链:交易系统开发指南》共分 7 章,第 1~2 章主要介绍区块链及数字货币的基本概念,以及各种公有链的 API 接口;第3~5 章主要介绍区块链交易系统的分类架构及功能; 6 章主要介绍区块链交易系统面临的问题及演进方向;第 7 章对全书做了总结。《区块链:交易系统开发指南》是...
  • 5.14加密货币价格:BTC突破6.2万美元以太坊和山寨币反映市场情绪

    5.14加密货币价格:BTC突破6.2万美元以太坊和山寨币反映市场情绪
    今天,随着比特币(BTC)的价格突破62 000美元的门槛,顶级加密货币的价格反弹了。 此外,以铁大幅上涨,维持在2 900美元的水平。 此外,其他顶尖山硬币,如索拉纳(SOL )、XRP、卡达诺(ADA )也大幅上涨。    今天密钥加密货币价格 1. 比特币价格    在5月14日星期二撰写本文时,比特币价格上升了2.57%,达到62 487.50美元。 另一方面,在过去24小时内,交易量从65.26 % 急剧上升至277亿美元。 与此同时,加密货币的市场价值为...
  • OKEx回应用户质疑:合约交易非期货 平台无机器人

    OKEx回应用户质疑:合约交易非期货 平台无机器人
       热点点 自选股份 数据中心 数据中心 研究和资料中心 资金流动 模拟交易 客户客户 具体来说,OKEx回答用户的问题:合同交易不是期货,平台不是机器人。 金融同步化,3月22日。    昨天下午,OKEx公司就维护先前用户线下的权利问题对同步财务公司作出了回应,指出OKEx公司提供的合同交易不是期货交易,在旗下的业务中没有正式的机器人。 同时,OKEX称,它不会以非法为由对任何投资损失索赔作出答复。 答复全文如下: 同步你的财务! 近日来,...
  • 0.00006694个比特币等于多少人民币/美金

    0.00006694个比特币等于多少人民币/美金
    0.00006694比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00006694比特币等于4.53424784美元/32.5436 16人民币。比特币(BTC)美元(USDT)人民币(CNY)0.000066944.53424784【比特币密码】32.82795436 16比特币对人民币的最新汇率为:490408.64 CNY(1比特币=490408.64人民币)(1美元=7.24人民币)(0.00006694USDT=0.0004846456 CNY)汇率更新时...
标签列表