手把手教你部署自己的uniswap交易所

资讯 2024-06-29 阅读:53 评论:0
Uniswap在Github上面开源了全部合约代码,其中包括,两部分.Uniswap还开源了前端代码,前端代码使用React开发Uniswap opened up all the contract codes on Github, incl...
美化布局示例

欧易(OKX)最新版本

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

APP下载   全球官网 大陆官网

币安(Binance)最新版本

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

APP下载   官网地址

火币HTX最新版本

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

APP下载   官网地址

Uniswap在Github上面开源了全部合约代码,其中包括,两部分.Uniswap还开源了前端代码,前端代码使用React开发

Uniswap opened up all the contract codes on Github, including two parts. Uniswap also opened up the front-end code, which was developed using React.

  • 核心合约
  • 周边合约
  • 前端代码

在Uniswap的核心代码中,主要包含3个合约:,,.其中配对合约继承了ERC20合约,我们可以把它们看作一个合约.工厂合约通过方法部署配对合约,所以在部署合约时.

In Uniswap's core code, there are three main contracts:...the pairing contract inherits the ERC20 contract, and we can see them as a contract. The factory contract deploys the pairing through the method, so when the contract is deployed...

周边合约中包括一些示例代码,例如价格预言机,闪电交换,其中最重要的是.在周边合约的代码库中,包含两个:,.工厂合约和配对合约需要通过路由合约调用才能更好的完成交易所的全部功能,所以我们

The adjoining contracts include a number of examples, such as price forecasters, lightning exchanges, the most important of which is... in the surrounding contract code library, there are two:...the factory contract and the pairing contract need to be called by route to better perform all the functions of the exchange, so we...

两个合约大部分相同,有小部分不同,如果将两个合约的差异化合并成一个合约,部署的时候将会出现,所以才被分成了两个合约.常用功能两个合约中都包括,所以我们部署其中任意一个路由合约都可以

The two contracts are mostly the same, there are minor differences, and if the differences between the two contracts are combined into one contract, they will occur at the time of deployment, so they are divided into two contracts. Both of the usual functions are included, so we can deploy any one of the route contracts.

代码语言:javascript
复制

如果你对合约代码并不熟悉,也可以跳过上面这部分,接下来我们将从以太坊浏览器中直接拷贝线上版合约源码

If you're not familiar with the contract code, you can skip this part. We're going to copy the contract code directly from the Etherno browser.

  • 工厂合约
  • 路由合约

我们可以使用truffle作为部署合约的环境,其他的环境也可以,如果已经安装过truffle可以跳过这一步

We can use truffle as an environment for deployment contracts, and other environments can skip this if they've been installed.

代码语言:javascript
复制
  • 初始化目录
代码语言:javascript
复制
  • 目录结构:
代码语言:javascript
复制

Uniswap的路由合约部署在以太坊的主网和Ropsten,Rinkeby,Goerli,Kovan几个测试网的,这样可以使Uniswap的前端不管切换到任何一个网络,路由地址都不会变.要想实现这个相同地址的部署,我们需要准备一个用来部署合约.全新的账户指的是在部署合约之前的.因为合约的地址是根据你的账户地址和nonce值计算出来的,所以在不同网络中,如果nonce值相同,部署出的合约地址也相同.

Uniswap's route contract is deployed on the Ethern main network and on the Ropsten, Rinkeby, Goerli, Kovan test network, which makes it possible for Uniswap's front end, regardless of switching to any network, to remain the same route address. To achieve the deployment of this same address, we need to prepare a contract for deployment. The new account refers to the pre-deployment contract. Since the contract's address is based on your account address and the nonce value, the contract address is the same in the different networks, if the nonce's value is the same.

通过助记词生成新账户

可以通过我之前录制的视频学习操作方法

You can learn how to do it through the video I recorded earlier.

  • B站视频
  • 油管视频

生成好助记词之后,记得用英文助记词,保存好助记词,还有助记词对应的账户地址

When you generate good notes, remember to use English notes, save good notes, and account addresses to which the notes correspond.

向新地址转帐ETH

部署合约需要的gas费约为0.18个Ether,目前主网可能需要的更多.

The cost of the deployment contract for Gas is approximately 0.18 Ether, which may be needed for the main network at this time.

通过一个已有Ether的账户向新账户转帐.测试网的Ether可以通过每个测试网的水龙头申请到测试币.

Transferred to a new account through an account that already exists with Ether. The Ether of the test network can apply for test money through the taps of each test network.

  • 获取测试币方法

在部署路由合约时,构造函数中需要填入工厂合约的地址和WETH合约的地址,由于WETH合约的地址在主网和测试网的地址都不相同,所以需要找到每个网络中WETH合约的地址.

At the time of deployment of the route contract, the construction function would have to fill in the address of the factory contract and the address of the WETH contract, and since the addresses of the WETH contract are not the same on the main network and the test network, the address of the WETH contract in each network would need to be found.

WETH合约用于将Eth交换为erc20的Eth,由于Eth不是erc20的token,所以我们必须使用WETH作为交换媒介

The WETH contract is for Eth swapping Eth to erc20. Since Eth is not erc20 token, we have to use WETH as a medium of exchange.

代码语言:javascript
复制

在部署合约之前,我们还需要使用infura作为免费节点,所以需要申请一个infuraKey

We need to use infra as a free node before deployment, so we need to apply for an infrakey.

  • 申请地址:infura.io
  • 申请方法

安装@truffle/hdwallet-provider模块,用于打开助记词的钱包,在项目目录中运行命令:

Installs the @truffle/hdwallet-provider module to open the wallet for helpwords and to run the command in the project directory:

代码语言:javascript
复制

如果我们需要在每个网络中都部署上Uniswap合约,就需要配置truffle-congif.js,可以将以下代码全部拷贝粘贴到文件中,覆盖原有代码.

If we need to deploy Uniswap contracts in every network, we need to configure truffle-congif.js and paste all of the following codes to the file to overwrite the original code.

然后别忘了修改和

And don't forget to modify and...

代码语言:javascript
复制
代码语言:javascript
复制

在编写truffle的部署脚本之前,先准备一个你的常用账户作为设置交易所手续费收取账户的管理员地址

Prior to the preparation of a deployment script for truffle, prepare an address for your usual account as the administrator for setting up an exchange charge.

然后在项目目录中运行命令,或者用编辑器创建文件migrations/2_deploy_contract.js

Then run the command in the project directory, or create files by editor(s)

代码语言:javascript
复制
代码语言:javascript
复制

在项目目录运行命令:

Run command in project directory:

代码语言:javascript
复制

现在我们就已经将Uniswap的路由合约和工厂合约都部署在所有的网络中了,你可以在控制台的信息中找到两个合约的地址,也可以在以太坊浏览器中找到,在以太坊浏览器中搜索新账户的地址,显示出来的新账户的交易信息中,将会显示两个创建合约的交易,,将路由合约的地址记录下来

Now that we've deployed Uniswap's route and factory contracts to all networks, you can find two contract addresses in the information on the control table, or in the Etherno browser, and search for the new account's address in the Etherno browser, showing the new account's transaction information, show the two transactions that created the contract, and record the route by the address of the contract.

在项目目录运行命令:

Run command in project directory:

代码语言:javascript
复制

在项目目录运行命令:

Run command in project directory:

代码语言:javascript
复制

安装完成后,可以先测试运行一下,在uniswap-interface目录运行命令

Once the installation is complete, you can test the running command at the uniswap-interface directory.

代码语言:javascript
复制

如果运行成功,将会打开一个浏览器,同时打开Uniswap的前端界面

If running successfully, a browser will be opened, along with a front-end interface for Uniswap

在Uniswap的前端中以常量的形式定义了Uniswap的路由地址,我们只需要修改路由地址就可以让前端链接到你的路由合约中

Uniswap's route address is defined in constant form in the front end of Uniswap, and we just need to change the route address to get the front end to your route contract.

修改文件: 第6行

Modify File: Line 6

代码语言:javascript
复制

保存后运行即可看到效果

You can see effects by running after saving

创建GitHub项目

创建项目的方法就不在这里讲了,不会的同学可以去搜索一下

It's not the way to create the project. No classmates can search it.

将前端代码添加到GitHub项目仓库

首先要删除原先Uniswap项目中的.git目录,在项目目录运行命令:

First, delete the.git directory from the original Uniswap project and run the command in the project directory:

代码语言:javascript
复制

然后初始化git,并将Unsiwap前端代码添加到自己的项目仓库中

Then initialize git and add Unsiwap frontend to its own project repository

代码语言:javascript
复制

安装并部署gh-pages

我们将通过gh-pages模块将前端代码部署到github.io,在前端代码的目录运行:

We will deploy the front-end code to github.io through the gh-pages module and run it in the directory of the front-end code:

代码语言:javascript
复制

接下来要编译react和部署gh-pages,在前端代码的目录运行:

Next is the compilation and deployment of the gh-pages, running in the directory of the front-end code:

代码语言:javascript
复制

修改前端代码目录中的package.json

Modify the package.json in the front-end code directory

代码语言:javascript
复制
代码语言:javascript
复制

保存退出之后,在前端代码的目录运行:

Runs the directory of front-end code after saving exit:

代码语言:javascript
复制

现在在浏览器中打开就可以打开自己的交易所啦. 如果不输入地址结尾的index.html在项目刚部署之后会报错,过一段时间就可以不输入了.

Open it in the browser now and open your own exchange. If you don't enter the index.html at the end of the address, you'll miss it after the project's deployment.

可以将以太坊浏览器中的weth源码拷贝下来,自己部署一个属于自己的weth合约

You can copy theweth code from the Taiwan browser and deploy yourself aweth contract of your own.

Uniswap有一个自己的可信token列表,同样被设置在文件中,在最后一行就是.你可以将这个链接地址的文件拷贝下来,设置成自己需要的可信token地址列表,然后上传到github目录中,再修改index.ts文件中的链接地址,这样就可以让你自己的交易所中拥有自己设置的可信token列表了

Uniswap has its own credible token list, which is also set in the file, and in the last line, you can copy the file of this link address and set it up as the credible token list you need, upload it to the github directory, and change the link address in the index.ts file, so you can have your own credible token list in your own exchange.

温馨提示:公众号中链接不可点,请戳“阅读原文”获取


本文作者:崔棉大师

Author: Maestro Choi

作者主页:

Homepage of author:

https://learnblockchain.cn/people/447


美化布局示例

欧易(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)汇率更新时...
标签列表