全部版块 我的主页
论坛 金融投资论坛 六区 金融实务版 比特币、区块链与元宇宙
634 1
2022-10-31

区块链中,交易信息以一个个信息块的形式记录,这些块以链条方式,按时间顺序连接起来。新生成的交易信息记录块,不断地被加到区块链中,交易一旦写入区块链中就不能被修改;

However,if an error occurs in the smart contract,the token may be stolen or a large amount of gas may be consumed,and the error must be repaired.However,the bug can only be repaired by redeploying the contract,which will cause a problem:the original contract has been used by many people.If a new contract is deployed,the data of the old contract will be lost.

去中心化

去中心化(Decentralized)的意思就是用户可以不通过Google、Facebook、微博等中介的服务访问互联网上的数据和信息,而是由个人自己拥有和控制互联网的各个部分。也就是说,在Web3上,开发者不需要在一个单独的服务器上建立和部署应用,也不用在一个单独的数据库中储存数据,极大降低了单点故障的风险。

Blockchain is the core of truly decentralized Internet.It has changed the way of data storage and management.Its unique architecture allows multiple nodes to keep consistent with the current state of the dataset without a centralized fact source.As the automatic execution code activated by users for decentralized execution,smart contracts are an important part of the encryption challenge,which allows two parties to transfer value without knowing each other.

gas费用

链上交易需要手续费,手续费被称为gas(汽油),gas是用于评估在区块链上执行特定操作所需的计算工作量的单位。

gas只是一个抽象单位,它仅存在于以太虚拟机中,用户实际上总是在以太网络中使用ETH(以太币)进行交易。

为什么要引入gas呢?

以太虚拟机可以执行任意代码,但它也更容易受到halting problem的影响。halting problem是指从一个任意计算机程序的代码和输入来确定该程序是会结束运行,还是会永远继续运行。如果没有gas,用户就可以执行一个永远不会停止的程序,为了防止这种情况发生,以太引入了与每个操作相关的gas成本,这将防止程序处于永远运行的状态,最终使整个网络陷入停滞状态。

DApp的基本架构图:

主要分为三个部分:

1、区块链以及本身提供的能力

2、三方钱包等提供的能力

3、我们要写的DApp部分----分为三个部分:

(1)和EVM交互的合约层--solidity编写;

(2)和合约层、钱包交互的交互层-web3js,其和Ajax类似,可以用来读取以太区块链,主要使用的JSON RPC和区块链进行通信,对区块链网络进行数据的读写操作;

(3)前端代码业务层-vue、react等编写;DAPP可以使用

DApp在被调用之前需要先部署到以太上,主要分为部署和调用两部分;

(1)部署

一个DApp可以由多个智能合约组成,因此部署一个DApp也就是同时部署多个智能合约,那么部署一个智能合约的流程图如下:

Smart contracts use RPC to call Ethernet wallets,Web3.js and other tools;Web3.js deploys the contract to the Solc compiler in Ethernet;The compiler returns the compiled bytecode;Send the contract bytecode and related parameters to the Ethernet node;The contract address and binary interface(ABI)are returned after the Ethernet node is deployed

(2)调用

部署好的合约可以进行调用,前端调用主要依赖MetaMask插件,前端的Web3 Provider是与特定的以太节点相连,可以直接使用

web3.currentProvider调用,下图展示了前端调用合约的一般流程。


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2022-11-29 11:10:39
点个赞感谢分享
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群