Defi/LP/DAPP代币合约流动性质系统/Solidity合约示例

供应商
广州杰肯狸网络科技有限公司
认证
联系电话
18125913365
手机号
19927739756
联系人
何经理
所在地
广州天河区中山大道
更新时间
2024-05-03 10:48

详细介绍

dapp,是基于***的底层**平台,被称为去中心化应用、分散式应用程序,所有数据都存储在分布式分类帐中。dapp自p2p网络开始以来就已经存在,其在不同计算机的p2p网络上运行,而不是在一台计算机上运行。dapp旨在系统-176搭建-0206+可电可微-5616以不受任何单个实体控制的方式在网络上运行。

  dapp can also be understood as an upgraded version of the app.theapp currently developed by the ios and android systems is taken outand thrown on the blockchain system.combined with smartcontracts,it becomes dapp.dapp firmly emphasizesdecentralization.it is necessary to run on a distributed operatingsystem and cannot work on traditional approaches such as androidand ios.dapp appears in many new distributed channels or networkssuch as ethereum and eos.it does not need to rely on any centralserver to achieve the purpose of decentralization.it can be runautomatically and the code is open source.in addition,dapp does notneed to be downloaded and installed.it directly jumps from theplatform to the application page to run.it can be opened and usedanytime and anywhere.it is easy to operate.

  

  dapp based on blockchain can solve the trust problem.dapp widelyuses the decentralized technology of smart contract,which can solvethe trust problem between users and dapp developers.it is to writethe protocol code into the smart contract,and then automaticallyexecute the contract content after certain conditions.the smartcontract realizes the credibility and transparency of the contractat the code level to ensure decentralization.the asset custody ofsmart contracts ensures the safe transaction of decentralized andtrusted assets.in the dapp of the decentralized exchange,userscompletely control their own assets.any transaction and transferare controlled by users,and the exchange cannot touch yourassets,which greatly reduces the trust risk with the exchange.

  

  去中心化,是互联网发展过程中形成的社会关系形态和内容产生形态,是相对于“中心化”而言的新型网络内容生产过程。在一个分布有众多节点的系统中,每个节点都具有高度自治的特征。节点之间彼此可以自由连接,形成新的连接单元。任何一个节点都可能成为阶段性的中心,但不具备强制性的中心控制功能。节点与节点之间的影响,会通过网络而形成非线性因果关系。这种开放式、扁平化、平等性的系统现象或结构,我们称之为去中心化。

  

  作为***诸多特性中的重要的一个特点,其使用分布式储存与算力,使得整个网络节点的权利与义务相同,系统中数据本质为全网节点共同维护,从而***不再依靠于中央处理节点,实现数据的分布式存储、记录与更新。

  

  dapp组件

  

  dapp的组件会有三个不同的类型:智能合约,前端逻辑(ui)和数据存储。

  

  智能合约

  

  智能合约存储了dapp的业务逻辑和当前的状态,这个是dapp和传统网络应用的*大区别,也正是因为这一点让dapp具备了以上提到过的优势。

  

  前端/ui

  

  尽管后端逻辑需要**者完成智能合约代码,并把它部署在***上,但是在前端,**者还是使用标准的网络技术,比如html和javascript,因此**者可以使用自己熟悉的工具,库和框架。

  

  第一步:创建智能合约:

  

  我们dapp中的智能合约是一个简单的例子,它可以查看数据并且反应出***上的变化。在这个例子中,我们会通过chainlinketh/usd喂价对查看eth/usd的价格,然后将结果存储在智能合约上。

  

  第一步是打开chainlink的文档,然后导航到using datafeeds页面。从这里将源代码复制进你的ide中的一个新的文件里(比如visual code),或者你可以点击“open inremix”按钮,然后使用在线ide remix。

  

  在这个例子中,我们会使用visual studio code和hardhat(一个evm**框架)。

  

  首先,为我们的dapp创建一个新的文件夹,并在这个文件夹中创建一个后端文件夹,用来存储智能合约代码:

  

  mkdir chainlink-dapp-example

  

  cd chainlink-dapp-example

  

  mkdir backend

  

  cd backend

  

  接下来,我通过vs code打开创建好的文件夹,然后安装hardhat:

  

  npm init-y

  

  npm install--save-dev hardhat

  

  npx hardhat

  

  (choose create javascript project,choose default parameters)

  

  当安装完成之后,在“contracts”文件夹中删掉touch.sol,然后在这个文件夹中创建一个叫做priceconsumerv3.sol的文件。在这个文件将存储我们的合约,所以将chainlink文档中的代码复制到这个文件中,然后保存。

  

  在样例代码中,你会看到demo合约已经有一个叫做getlatestprice的功能来通过rinkeby上的eth/usd喂价对查看ethereum的当前价格。

  

  function getlatestprice()public view returns(int){

  

  (

  

  /uint80 roundid/,

  

  int price,

  

  /uint startedat/,

  

  /uint timestamp/,

  

  /uint80 answeredinround/

  

  )=pricefeed.latestrounddata();

  

  return price;

  

  创建一个新的变量和函数,在智能合约上储存这个值。

  

  int public storedprice;

  

  然后,创建一个新的函数,它会被dapp的前端调用。这个函数会通过调用getlatestprice函数查看ethereum的*新价格,然后将这个值存储在storedprice这个参数中:

  

  function storelatestprice()external{

  

  storedprice=getlatestprice();

  

  }

  

  你的新的合约应该和下面的一样:

  

  //spdx-license-identifier:mit

  

  pragma solidity^0.8.7;

  

  import"chainlink/contracts/src/v0.8/interfaces/aggregatorv3interface.sol";

  

  contract priceconsumerv3{

  

  aggregatorv3interface internal pricefeed;

  

  int public storedprice;

  

  /**

  

  *network:rinkeby

  

  *aggregator:eth/usd

  

  *address:0x8a753747a1fa494ec906ce90e9f37563a8af630e

  

  */

  

  constructor(){

  

  pricefeed=

  

  aggregatorv3interface(0x8a753747a1fa494ec906ce90e9f37563a8af630e);

  

  }

  

  /**

  

  *returns the latest price

  

  */

  

  

  (

  

  /uint80 roundid/,

  

  int price,

  

  /uint startedat/,

  

  /uint timestamp/,

  

  /uint80 answeredinround/

  

  )=pricefeed.latestrounddata();

  

  return price;

  

  }

  

  function storelatestprice()external{

  

  storedprice=getlatestprice();


展开全文

我们其他产品
我们的新闻
优质商家推荐 拨打电话