today I'm going to show you how to build an entire blockchain application from 今天，我将向您展示如何从中构建整个区块链应用程序
start to finish we're gonna build a crypto currency 开始完成，我们要建立一种加密货币
exchange where you can buy and sell crypto currencies at a fixed price and 以固定价格买卖加密货币的交易所，以及
I'll walk you through everything step by step we'll set up a blockchain on our 我将逐步引导您完成所有工作，我们将在我们的平台上建立一个区块链
computer right to aetherium smart contracts we'll write tests against them 计算机获得以太坊智能合约的权利，我们将针对它们进行测试
and finally we'll create a client-side website where anyone can connect to the 最后，我们将创建一个客户端网站，任何人都可以连接到
exchange and buy and sell crypto currencies and you might be thinking I 交换和买卖加密货币，您可能会想我
don't even understand what a blockchain is or how it works that's okay I'm gonna 甚至不了解区块链是什么或它如何工作，没关系，我要
show you everything you need to know before we start coding so really quickly 向您展示您在开始编码之前非常需要了解的所有内容
if you're new around here hey I'm Greg arrays from dab University and on this 如果您是这里的新手，我是dab大学的Greg阵列
channel I teach you how to become a blockchain master so if that's something 我教你如何成为区块链大师的渠道，如果那是某件事
that you're interested in then click the like button down below and click 您感兴趣的内容，然后单击下面的“赞”按钮，然后单击
Subscribe and if you like this tutorial and you're serious about becoming a 订阅，如果您喜欢本教程，并且认真考虑成为一名
blockchain developer then head on over to DAP in your virtual com4 slash 区块链开发人员然后以虚拟com4斜杠转到DAP
bootcamp alright so before we start building the project let me explain how 训练营好吧，所以在我们开始构建项目之前，让我解释一下
a blockchain works and how we're gonna use it in this tutorial so what is a 区块链的工作原理以及我们将如何在本教程中使用它，所以什么是
blockchain well to answer this question let's look at how a normal web 区块链很好地回答了这个问题，让我们看看普通的网络
application works normally when you use a web application you access it with 当您使用Web应用程序访问Web应用程序时，该应用程序正常工作
your browser and that web browser talks to a central server this server hosts 您的浏览器，并且该网络浏览器与该服务器托管的中央服务器对话
all the code for the web application and all the data is stored inside of a Web应用程序的所有代码和所有数据都存储在一个
central database this presents a real problem you can't store value this way 中央数据库提出了一个真正的问题，您无法通过这种方式存储价值
for example you couldn't create a digital currency with a traditional web 例如，您无法使用传统网络创建数字货币
application why is that see the code can be changed by the developers at any time 应用程序为什么看到代码可以由开发人员随时更改
and the data and the database can also be changed arbitrarily with anyone who 数据和数据库也可以由任何
had access to it this means that whoever controls the 有权使用它，这意味着谁控制
money could manipulate your balance and steal your funds so we don't want to use 金钱可能会操纵您的余额并窃取您的资金，所以我们不想使用
a centralized web application to create money instead we want to use the 一个集中化的Web应用程序来赚钱，而我们想使用
blockchain it will guarantee that no one can change the code for the application 区块链，它将确保没有人可以更改应用程序的代码
or manipulate the database we can rest assured that our money will always work 或操作数据库，我们可以放心，我们的钱将永远可用
in a predictable way and that our funds won't be stolen how can we achieve this 以一种可预测的方式，并且我们的资金不会被盗，我们如何才能实现这一目标
you might ask to answer this question let's look at how a blockchain works a 您可能会想回答这个问题，让我们看一下区块链的工作原理。
blockchain is basically just a giant world wide computer instead of a single 区块链基本上只是一台巨型全球计算机，而不是一台
that stores data and runs programs blockchains used thousands of computers 存储数据并运行程序的区块链使用了数千台计算机
that all handle this each computer is called a node and each node talks to one 所有处理此事的每台计算机都称为一个节点，并且每个节点都与一个节点通信
another and each node also gets a copy of all the data and all the code that's 另一个，每个节点还获得所有数据和所有代码的副本
stored on the blockchain all this data is stored in bundles of Records called 存储在区块链上的所有这些数据都存储在称为
blocks which are changed together to make up the public ledger and all the 一起改变以组成公共分类帐和所有
code is stored in smart contracts which are immutable code that runs in the 代码存储在智能合约中，这些合约是运行在
blockchain this creates endless possibilities for a 区块链为
new generation of applications not controlled by anyone but instead run by 新一代应用程序不受任何人控制，而是由
them sells on the blockchain cryptocurrency is a great example you 他们在区块链加密货币上出售是一个很好的例子
can create a cryptocurrency with a blockchain because each node in the 可以使用区块链创建一种加密货币，因为
network is responsible for processing your transaction and tracking your 网络负责处理您的交易并跟踪您的
balance whenever you send a cryptocurrency the network achieves 每当您发送网络达到的加密货币时均达到平衡
consensus that your transaction is valid and that your balance is updated 关于您的交易有效且余额已更新的共识
properly on the public ledger now let's look at how a basic blockchain 正确地在公共分类帐上，现在让我们看一下基本的区块链
application or add app works for this tutorial we're going to use the etherium 应用程序或添加应用程序适用于本教程，我们将使用etherium
blockchain to access the application you'll use your browser to connect to a 区块链访问应用程序，您将使用浏览器连接到
front-end website written an HTML CSS and JavaScript and instead of talking to 前端网站写了HTML CSS和JavaScript，而不是交谈
a back-end web server this website will talk directly to the blockchain this is 后端Web服务器，该网站将直接与区块链对话，这是
where all the code and the data for the application will live the code is 该应用程序的所有代码和数据将在其中保存的位置是
contained in smart contracts which are written in the solidity programming 包含在固体程序中编写的智能合约中
language which looks a lot like JavaScript these smart contracts are 这些看起来很像JavaScript的语言这些智能合约是
immutable which means they cannot change and all the data is stored inside of 不可变的，这意味着它们无法更改，所有数据都存储在内部
transaction records on the public ledger which is also immutable anytime we add 我们在任何时候添加的公共账本上的交易记录都是不变的
new data to the blockchain it will be permanent and publicly verifiable so 区块链中的新数据将是永久性的且可公开验证的，因此
that's an overview of what a blockchain is and how it works now let's get a 这是关于什么是区块链及其工作原理的概述
preview of the application that we're gonna build together in this tutorial 我们将在本教程中一起构建的应用程序的预览
and see how it leverages the power of the blockchain this is an instant 看看它如何利用区块链的力量，这是一个瞬间
cryptocurrency exchange called eath swap where you can trade cryptocurrencies at 称为Eath交换的加密货币交易所，您可以在此处交易加密货币
a guaranteed price you can buy and sell cryptocurrencies immediately without 您可以立即购买和出售加密货币的保证价格
having to open any buy or sell orders or wait for anyone else to fill your orders 必须打开任何买卖订单或等待其他人填写您的订单
inside this application we're gonna trade two different 在此应用程序内，我们将交易两种不同的
cryptocurrencies the first is ether the native cryptocurrency of the etherium 加密货币首先是以太坊以太坊的原生加密货币
blockchain and the second is DAP token a cryptocurrency that will create together 区块链，第二个是DAP令牌，它将一起创建一个加密货币
in this tutorial our applications will allow us to purchase DAP tokens with 在本教程中，我们的应用程序将允许我们通过以下方式购买DAP令牌：
ether like this we'll just specify the amount that you want to purchase click 像这样的以太币，我们只指定您要购买的数量click
swap and we'll see our depth token balance go up and we'll also be able to 交换，我们将看到深度令牌余额增加，并且我们还能够
sell the DAP tokens in a different tab like this and you can see that the 像这样在其他标签中出售DAP令牌，您可以看到
cryptocurrencies change here and we'll also highlight the redemption rate you 加密货币在这里发生变化，我们还将突出显示您的兑换率
know the price right and then also the account that were connected to on the 知道价格权，然后知道连接到的帐户
blockchain along with an IDenticard that represents the user's avatar here's a 区块链以及代表用户头像的IDenticard，这是一个
diagram of how the application will work we'll build a client-side application in 该应用程序如何工作的示意图，我们将在其中构建一个客户端应用程序
react j/s that's what you see here and then this client-side application is 对j / s做出反应，这就是您在此处看到的，然后此客户端应用程序
going to talk directly to the blockchain alright and then the blockchain will 将直接与区块链对话，然后区块链将
contain two different smart contracts the first smart contract will be the 包含两个不同的智能合约，第一个智能合约将是
east swap contract that facilitates purchasing tokens and also selling them 东交换合约，方便购买代币并出售
and then that smart contract will talk to a second smart contract which will be 然后该智能合约将与第二个智能合约进行对话
the token that we create in this tutorial in this case the DAP token now 我们在本教程中创建的令牌（在本例中为DAP令牌）
let's install all the dependencies that we need for blockchain development 让我们安装区块链开发所需的所有依赖项
the first is no js' you can see if you haven't already installed by going to 首先是没有js'，您可以通过以下方法查看是否尚未安装
your terminal and typing node - V if you don't have node installed yet you can 您的终端并输入节点-V（如果尚未安装节点）
install it with a command-line tool like homeroom or you can download it directly 使用命令行工具（例如homeroom）进行安装，也可以直接下载
from a node.js website just like this for this tutorial I'm gonna stick with 来自node.js网站，就像本教程一样，我会坚持
node version 9 10.0 and I suggest that you do the same the next dependency is 节点版本9 10.0，我建议您执行相同操作，下一个依赖项是
ganach this is a one click block chain that runs on your computer I'll put a ganach这是在您的计算机上运行的一键式区块链，我将
link down in the description below where you can download this but when you go 链接到下面的描述中，您可以在此处下载此文件
here you can just click this download button and it will automatically select 在这里，您只需单击此下载按钮，它将自动选择
the correct installer for your operating system whether you're on Mac Windows or 无论您是在Mac Windows上还是在Windows上，都需要正确的操作系统安装程序
Linux and once you've downloaded it and you start it you'll have a blockchain Linux，一旦下载并启动，您将拥有一个区块链
running on your computer and you can see that it gave you 10 accounts for free 在您的计算机上运行，​​您可以看到它免费提供了10个帐户
and each of these accounts has been pre funded with cryptocurrency in their 并且这些帐户中的每一个都已经在其帐户中预先注入了加密货币
wallet so in this case it's ether or the native 钱包，在这种情况下是以太币或本地人
cryptocurrencies of the etherium blockchain that's what this represents 这就是以太坊区块链的加密货币
and this you know cryptocurrency isn't worth anything this is just you know 而且这你知道加密货币不值钱，这只是你知道
pretend cryptocurrency for development purposes but you can see the accounts 假装用于开发目的的加密货币，但您可以看到帐户
address here and then also you can click this to reveal the private keys and 地址，然后您也可以单击此处以显示私钥和
finally I'll say don't use these accounts in the real world because you 最后我会说不要在现实世界中使用这些帐户，因为您
know everyone who's watched this video has seen these private keys and you 知道每个观看此视频的人都看到了这些私钥，而您
don't want to compromise your funds the next dependency is the truffle framework 不想损害您的资金下一个依赖是松露框架
this is a smart contract development framework where we'll be able to create 这是一个智能合约开发框架，我们可以在其中创建
aetherium contracts with a solidity programming language we'll also be able aetherium使用坚固的编程语言签约，我们也将能够
to write tests against the smart contracts and deploy them to a 针对智能合约编写测试并将其部署到
blockchain I'm going to use a very specific version of truffle in this 区块链中我将使用非常特殊的松露版本
tutorial and I suggest that you do the same I'm gonna get my terminal and type 教程，我建议您执行相同的操作，然后输入我的终端并输入
in NPM install - - G truffle at version 5.1.1 4 click enter and finally we must 在NPM安装中--G松露版本5.1.1 4单击Enter，最后我们必须
install meta mask this is a browser extension that will turn our normal web 安装meta mask，这是一个浏览器扩展程序，它将使我们的网站正常运行
browser into a blockchain browser you can go to the Google Chrome Web Store to 浏览器进入区块链浏览器，您可以转到Google Chrome网上应用店
find meta mask and just click install I've already done it so I have the 找到元掩码，然后单击“安装”，我已经完成了，所以我有了
remove button but if you don't have it yet you should see the install button 删除按钮，但如果还没有，则应该看到安装按钮
alright and once you walk through the setup steps go to your Chrome extensions 好的，完成设置步骤后，请转到您的Chrome扩展程序
and make sure that you have meta mask and able you can tell that it's enabled 并确保您具有元掩码，并能够告诉您已启用它
by seeing the Fox icon up in the right-hand corner of your browser 通过查看浏览器右上角的Fox图标
now let's start building the project instead of setting everything up 现在让我们开始构建项目，而不是进行所有设置
manually we're gonna use a template that i've created called the dap university 手动，我们将使用我创建的名为dap大学的模板
starter kit you can find this link down in the description below but copy this 入门套件，您可以在下面的说明中找到此链接，但请复制该链接
URL and go to your terminal and say git clone and then paste in the URL alright URL，然后转到您的终端并说出git clone，然后粘贴URL
and then hit space and create your project name in this case I'm gonna call 然后敲打空间并在这种情况下创建您的项目名称
it swap and now I'll enter into that newly created directory like this I'll 它交换，现在我将进入新创建的目录，如下所示
say CDE swap and I'll install the project dependencies with NPM like this 说CDE交换，我将像这样用NPM安装项目依赖项
say NPM install alright once that's finished you should see a success 说NPM安装正确，一旦完成，您应该会看到成功
message here don't worry if you see a bunch of warnings here it's not ideal 这里的消息请不要担心，如果您在这里看到一堆警告，那是不理想的
but they are just warnings for now you'll know that it completed 但它们只是警告，您现在知道它已完成
successfully if you have a message like this all right so really quickly before 成功，如果您收到这样的消息，那么很快就可以
we move on I want to install one more dependency that's not included in the 我们继续，我想安装一个不包含在其中的其他依赖项
project yet ok so if I go back to the application preview you can see these 项目还可以，所以如果我返回到应用程序预览，可以看到这些
things right here these are called identic cons and we want to install a 这些东西在这里被称为idents缺点，我们想安装一个
special library that it helps us to create those so we're gonna use identic 特殊的库，它可以帮助我们创建那些库，因此我们将使用相同的库
on j/s let's see if I can find it here here it is so this library is gonna 在j / s上，让我们看看是否可以在这里找到它，因此该库将
allow us to create these identic ons based on the users of theorem address 允许我们基于定理地址的用户创建这些恒等式
all right so we can install identic on jeaious like this we'll say npm install 好的，这样我们就可以在jeaious上安装identic，我们会说npm install
- - save identic on a s @ and then carrot version 2.3.3 alright now let's -将identic另存为@，然后选择胡萝卜版本2.3.3，现在让我们
get a quick tour of the project I'm gonna open this in my text editor I'm 快速浏览项目，我将在文本编辑器中打开它
going to use sublime text so I've configured a special command on my 将使用崇高的文字，因此我在自己的电脑上配置了一个特殊的命令
computer to open the project in sublime text like this alright it's a simple dot 像这样的计算机以高品质的文本打开项目
this is a truffle project where we have everything we need to create smart 这是一个松露项目，我们拥有创造聪明所需的一切
contracts right tests against them deploy them to a blockchain and also 针对他们的合同权利测试将它们部署到区块链
create our client-side web site all right so I'm going to show you what's 可以正常创建我们的客户端网站，所以我将向您展示
inside of here the first place to take note is the 在这里，首先要注意的是
truffle - config file this is the main entry point for the application where we 松露-配置文件，这是应用程序的主要入口点
specify our connection to the blockchain the 指定我们与区块链的连接
shows the development network that connects to ganache this tells us which 显示了连接到ganache的开发网络，这告诉我们
you know compiler we want to use to compile the smart contracts and then 您知道我们要使用的编译器来编译智能合约，然后
also it shows us where the smart contracts live inside the project so if 它也向我们展示了智能合约在项目内部的位置
you've used truffle before this may look a little new to you that's because I've 您已经使用过松露，在您看来这有点新，因为我
configured this project to automatically put the smart contracts at a different 配置该项​​目以自动将智能合约置于其他位置
place than where they normally are in the project that's because I want to 比他们通常在项目中所处的位置更重要，因为我想
access those smart contracts from the client-side application that we'll build 从我们将构建的客户端应用程序访问那些智能合约
in this tutorial you'll see that more at play here in a minute so I'll just show 在本教程中，您将在一分钟内看到更多正在播放的内容，因此我只展示
you the smart contracts are inside the source contracts directory we can see 您智能合约位于源合约目录中，我们可以看到
this migration contract that's already here this is a smart contract that comes 这个已经存在的迁移合同这是一个聪明的合同
with every truffle project that basically just handles deploying 每个松露项目基本上只负责部署
other smart contracts to the blockchain so don't worry really too much about 其他智能合约到区块链，所以不必担心太多
what's happening inside of here just know that this comes standard with 里面发生的事情只知道这是标准配置
truffle projects and you don't have to edit this code or really even understand 松露项目，您无需编辑此代码，甚至无需了解
it next you can see a components directory this is where all the 接下来您可以看到一个组件目录，这是所有
application code for the clients that application will live you know this is 该应用程序将运行的客户端的应用程序代码，您知道这是
react.js code so react organizes all of its all of its code into these reusable react.js代码，以便react将其所有代码组织成这些可重用的代码
components which we'll talk more about when we get to the client side portion 我们将在客户端部分讨论更多组件
of this tutorial but I wanted to just make note of that here all right and 本教程的内容，但我想在这里记一下，
then next we have a migrations directory this is where we'll create migrations to 接下来，我们有一个迁移目录，这是我们将创建迁移到的目录
put the smart contracts on the blockchain we'll talk about that more 将智能合约放在区块链上，我们将进一步讨论
when we get to that and then finally the package JSON file this is where we 当我们到达那里，最后是包JSON文件时，这就是我们
specify all the project specific dependencies that we need in order to 指定我们需要的所有特定于项目的依赖项
build the project and also while we're inside of here we can you know change 建立项目，并且当我们在这里时，我们可以知道更改
this name to see your eath swap alright and we'll just say an instant ERC 20 这个名字看你的食堂交换好了，我们就说即时ERC 20
cryptocurrency exchange 加密货币交换
all right and we can also see the identic Khan library that we added 好的，我们还可以看到我们添加的相同的Khan库
manually via the command line right here so next let's go ahead and boot up the 在此处通过命令行手动进行操作，因此接下来让我们继续启动
web server for the project just to make sure that it was installed properly I'm 该项目的Web服务器只是为了确保它已正确安装
gonna open up a new terminal tab to do this alright and I'm gonna say NPM run 要打开一个新的终端标签来执行此操作，我要说NPM运行
start and that should automatically start the webserver and open up the 启动，这应该会自动启动网络服务器并打开
website the client-side website and a new browser tab boom there we go 网站，客户端网站和新的浏览器标签热潮
so this is what was installed this was the DAP University starter kit so you 这就是DAP大学入门套件，所以您已经安装了
can see this already looks really nice it has some styling already that's 可以看到它已经看起来非常不错，它已经具有一些样式
because we're using the bootstrap templating framework you can see a nav 因为我们使用的是引导模板框架，所以您可以看到一个导航
bar here with a nice dark color the DAP University logo and everything you know DAP大学徽标以及您所知道的一切都带有深色
has some nice-looking fonts and stuff like that we're gonna be able to use 有一些漂亮的字体和类似的东西，我们将能够使用
bootstrap to avoid writing really any CSS in this tutorial it'll make our 避免在本教程中编写任何CSS的自举，它将使我们
application look really nice and eventually like this without having to 应用程序看起来真的很好，最终不必像这样
do too much coding so whenever we create the client-side website essentially 做太多的编码，所以无论何时我们实质上创建客户端网站
we'll start here inside the app J's directory and modify this code you know 我们将从应用J的目录开始，然后修改此代码
you can see this is all the code that currently generates the starter kit that 您可以看到这是当前生成入门工具包的所有代码，
we see here all right so I'm gonna leave this for now we'll come back to this 我们在这里看到没事，所以现在我要离开这个，我们将回到这个
whenever we create the client-side portion of the application but I'm just 每当我们创建应用程序的客户端部分时，我只是
gonna leave the web server here running in a separate tab and don't forget about 会将Web服务器留在此处在单独的选项卡中运行，并且不要忘记
it whenever we come back I'll remind you we 每当我们回来的时候，我都会提醒你我们
build that part of the application but next I'm going to do is go ahead and 构建应用程序的该部分，但接下来我要做的是
start developing the smart contracts and we'll use you know our primary terminal 开始开发智能合约，我们将使用您知道的主要终端
tab for this and then leave the web server running in the background okay 标签，然后让Web服务器在后台运行
I'll create a new file for the smart contract like this I'll say touch let's 我将像这样为智能合约创建一个新文件，我会说touch let
see here source contracts and we'll say cap OE eath capital s swap Sol alright 看到这里的源合同，我们将说OE资本上限互换资本Sol好
and you can do this from your text editor if you want to you don't have to 如果您不需要，可以从文本编辑器中执行此操作
do it from the command line but if you look here we've got a source contracts 从命令行执行此操作，但是如果您在此处查看，我们已经签订了源合同
you'll see this eath swap file that was created inside of here is where we're 您会看到在此内部创建的食堂交换文件
gonna write all the solidity source code for the smart contract okay so we can 会为智能合约编写所有的可靠性源代码，这样我们就可以
start off by doing this we can say pragma solidity 通过这样做我们可以说实用主义的坚固性
I'll use a carrot oh sorry it's a version 0.50 all right so what this does 我会用胡萝卜哦，对不起，它是0.50版，所以这可以做什么
is it declares the solidity programming language version that we want to use so 是它声明了我们要使用的统一编程语言版本吗
the next thing that we do is create the smart contract like this we say contract 接下来我们要做的就是创建像这样的智能合约
each swap all right then we use some curly braces and inside these curly 每次交换都正确，然后我们使用一些花括号，并在这些花括号内
braces is where we'll write all of the code for the smart contract they'll say 花括号是我们将为他们说的智能合约编写所有代码的地方
that it belongs to this contract named eath swap alright so the first thing 它属于这个名为Eath swap的合同，所以第一件事
that I want to do is just create a really simple test or a demonstration to 我想要做的就是创建一个非常简单的测试或演示
see how it works and what we're gonna do is create a name for the smart contract 看看它是如何工作的，我们要做的是为智能合约创建一个名称
and we'll do this with a variable like this 我们将使用这样的变量来执行此操作
all right so we'll say name equals eath swap instant exchange all right and now 好的，所以我们将说名称等于eath swap立即交换
you know this is a string which basically just means it's a 你知道这是一个字符串，基本上就意味着它是一个
human-readable you know set of characters like this 人类可读的，你知道这样的字符集
inside of these quotation marks and we must follow each line with a semicolon 在这些引号内，我们必须在每行后加上分号
like this okay and then finally we must tell solidity what type this is all 这样好吧，最后我们必须告诉Solidity这是什么类型
right because it's a statically typed language so it's a string name okay so 对，因为它是一种静态类型的语言，所以它是一个字符串名称，所以
it can't be a number later or something like that it always has to be a string 以后不能是数字，也不能总是类似字符串
and then finally what we want to do is read this variable value outside of the 最后我们要做的是从
smart contract so we must call it public all right 智能合约，所以我们必须将其称为公开
so string public name equals you know the string swap instant exchange 所以字符串公共名称等于您知道字符串交换即时交换
followed by semicolon so this actually creates a lot of functionality for us in 其次是分号，因此这实际上为我们创建了很多功能
one simple line of code which we'll see here in a minute because we declare this 一小段代码，我们将在一分钟内在这里看到，因为我们声明了这一点
public solidity is going to give us a function that we can call on the smart 公共团结将为我们提供可以调用智能功能的功能
contract called name which is going to return this value okay and you know 名为name的合同将返回此值，您知道
there are different visibilities and functions which we'll see later and 有不同的可见性和功能，我们将在后面看到，
solidity in this tutorial but this basically just means that if we didn't 坚固性，但这基本上只是意味着，如果我们不
have this we wouldn't be able to read that name value later out 有了这个，我们以后将无法读取该名称值
the smart contract but because we do we'll be able to read this like in the 智能合约，但是因为我们这样做，我们将能够像在
console which I'm going to show you here right now alright so let's just see if 控制台，现在我将在这里向您展示，所以让我们看看
we can put this smart contract on the blockchain and interact with it in the 我们可以将此智能合约放在区块链上并在
console just to see that the project's set up properly so what we'll do is go 控制台只是为了查看项目的设置正确，所以我们要做的就是
to the migrations directory alright and you see this initial migrations file 到迁移目录好了，您会看到此初始迁移文件
we're going to create a new file here and we'll call it - all right I'll call 我们将在这里创建一个新文件，我们将其命名为-好的，我将其命名为
it deploy contracts ijs all right so let me tell you what these migration files 它可以部署合同ijs，所以让我告诉您这些迁移文件是什么
do essentially they just take a contract a smart contract and put them on the 实际上，他们只是签了一份智能合约，然后将其放在
blockchain so that's what this code does and truffle basically has these things 区块链，这就是这段代码的作用，松露基本上具有这些东西
called artifacts which are you know kind of JavaScript versions of the smart 所谓的工件，您知道智能的JavaScript版本
contracts with JSON and you know you're able to sign them to variables like this 与JSON签约，并且您知道可以将其签名为这样的变量
and JavaScript and truffles deployer notice how to put them on the blockchain 和JavaScript和松露部署者注意到如何将它们放入区块链
like this alright so essentially we're just going to follow this pattern and 像这样，所以基本上我们将遵循这种模式，
copy and paste this you don't have to like reinvent the wheel here so I'm just 复制并粘贴这个，您不必在这里重新发明轮子，所以我只是
gonna do that put it in the deploy contracts directory and say eath swap 要做的就是把它放在deploy contract目录中，并说Eath swap
alright so that's just gonna swap the saara it's gonna fetch the east swap 好吧，那只是交换掉交换区，就可以得到东交换
contract we just created and put it on the blockchain so lastly I'll say that 我们刚刚创建的合同并将其放在区块链上，所以我最后要说
migration files inside of truffle are a lot like you know migrations that you 松露内部的迁移文件非常像您知道的迁移
might have seen in another context if you're if you're a developer already so 如果您已经是开发人员，那么可能已经在其他情况下看到了
maybe you've seen a migration to change a database like with sequel or MongoDB 也许您已经看到过迁移以更改数据库，例如续集或MongoDB
something like that where you're essentially creating new tables or 类似这样的东西，您实际上是在创建新表，或者
something like that maybe adding columns it's the same thing in shuffle 诸如此类，也许添加列在洗牌中是一样的
so in those contexts you know you're migrating the state of a database from 因此，在这些情况下，您知道您正在从以下位置迁移数据库状态
one state to another or you're adding new tables in this case you're also 一种状态到另一种状态，或者在这种情况下要添加新表
changing the blockchain state from one state to another and also you're 将区块链状态从一种状态更改为另一种状态
technically migrating smart contracts from your development environment to a 从技术上将智能合约从您的开发环境迁移到
blockchain okay so that's that's a few different ways you can 区块链好吧，那就是几种不同的方式
think about it before you run the migrations make sure that you have 在运行迁移之前先考虑一下，确保您拥有
ganache running right so don't forget this is your development blockchain so ganache运行正确，所以不要忘记这是您的开发区块链，所以
find wherever you installed it and open it and make sure that it's running you 找到安装它的位置并打开它，并确保它正在运行
might see like a Quick Start button or something like that go ahead and click 可能看起来像“快速启动”按钮或类似的内容，然后单击
that and when you see a page like this with the accounts and their balances 那，当您看到这样的页面，其中包含帐户及其余额
you'll know that ganache is ready to go and that you're connected to it at the 您会知道ganache已准备就绪，并且已在
right port seventy five forty five you know right here inside your truffle 正确的端口七十五四十五你知道在松露里面
project now that that's finished we can migrate the smart contracts like this 现在完成项目，我们可以像这样迁移智能合约
and put them on the block chains we just go to the terminal and say truffle 然后把它们放在区块链上，我们只是去码头说松露
migrate all right and there you go you can see that it first compiled the smart 正确迁移，然后您就可以看到它首先编译了智能
contracts it started the migration process the initial migration contract 它开始迁移过程的合同初始迁移合同
was deployed and then finally our each swap contract was also deployed okay the 被部署，最后我们的每个交换合同也被部署好了
next thing we want to do is interact with the smart contract in the 我们接下来要做的是与
development console like this we just open it by saying truffle console all 像这样的开发控制台，我们只是说松露控制台全部打开它
right this is going to give us a JavaScript environment where we can you 对，这将为我们提供一个JavaScript环境，我们可以在这里
know write JavaScript commands that will interact with the blockchain and also 知道编写将与区块链交互的JavaScript命令
interact with the smart contract that we just created so I'm going to fetch the 与我们刚刚创建的智能合约进行交互，因此我将获取
smart contract like this all right we say contract equal oh wait 这样的智能合约好吧，我们说合约相等哦，等等
swap got deployed all right and sometimes people get confused because I 交换部署得很好，有时人们会感到困惑，因为我
say undefined here but we can simply access the contract like this we just 在这里说未定义，但是我们可以像这样访问合同
retype the contract variable contract all right boom there we go and we can 重新输入合同变量合同，好吧繁荣，我们去了，我们可以
fetch the contract address like this we say contract address all right and then 这样获取合同地址，我们说合同地址没问题，然后
we can fetch the contract name like this we just say name equals a wait contract 我们可以这样获取合同名称，我们只说名称等于等待合同
name followed by two open and closed parenthesis all right 名称，后跟两个开放式和封闭式括号
so no parenthesis here but parentheses here and we say name boom there we go 所以这里没有括号，但这里是括号，我们说那里有名字繁荣
ease swap instant exchange perfect so really quickly I'll explain a few things 轻松进行交换，即时交换完美无缺，所以我很快会解释一些事情
here first is the contract address so if you open ganach you'll see that you know 这里首先是合同地址，所以如果您打开ganach，您会看到您知道
you have accounts already here on the blockchain and these 您已经在区块链上拥有帐户了，这些
have addresses these essentially represent the users on the blockchain 这些地址实际上代表了区块链上的用户
you know the addresses were like a username and the private key is sort of 您知道地址就像一个用户名，私钥有点
like a password right so the same is true for smart contracts they also have 像密码一样，因此对于智能合约也是如此
addresses so essentially this just tells it the location or kind of like the 地址，从本质上讲，这只是告诉它的位置或种类
username of the smart contract on the blockchain so yeah that's what this is 区块链上智能合约的用户名，是的，这就是
right here the other thing I want to explain is this a weight keyword 在这里，我要解释的另一件事是这是一个weight关键字
alright so whenever you're interacting with the blockchain a lot of times you 好吧，所以每当您与区块链互动很多次时，
know especially in JavaScript you're you're doing a synchronous 尤其是在JavaScript中，您正在同步
interactions which essentially means that the function calls a lot of times 相互作用，这实际上意味着该函数调用了很多次
don't actually return the value that you're asking for so for example when 实际不返回您要的值，例如
you say name if I just did like name equals contract name this wouldn't work 你说名字，如果我只是喜欢名字等于合同名，那是行不通的
this wouldn't actually return the contract name it would return something 这实际上不会返回合同名称，而是会返回某些内容
called a promise okay and a promise is a way for JavaScript to 所谓的Promise可以，而Promise是JavaScript的一种方式
handle asynchronous function calls okay so what we can do is wait for the 可以处理异步函数调用，所以我们可以做的就是等待
promise to resolve and say oh wait you know contract name and that will 承诺解决并说出来哦，等等您知道合同名称，那将
actually do what it says it'll wait for it to finish and we'll get the value of 实际执行它说的事情，它会等待它完成，我们将获得
the name like that okay just so just notice that you know that won't actually 这样的名字好吧，只是请注意，您知道实际上并不会
return the name but this will so there's lots of a ways to handle asynchronous 返回名称，但这将使有很多处理异步的方法
function calls in JavaScript you can use promise chains use callback functions 您可以使用JavaScript中的函数调用使用诺言链使用回调函数
you can read more about that online if you want to but just notice that you 您可以在线阅读更多有关该内容的信息，但请注意，
know whenever you're interacting the blockchain a lot of times you have to do 知道很多时候您需要与区块链进行交互
these asynchronous actions because the blockchain is slow and you know there's 这些异步动作，因为区块链很慢，而且您知道
multiple strategies for handling that but we're gonna pretty heavily use the 多种策略来处理该问题，但我们将大量使用
async await pattern in this tutorial now we've created a basic file for our eat 在本教程中，异步等待模式现在我们已经为进餐创建了一个基本文件
swap smart contract okay this is gonna be the contract where we create buying 交换智能合约好吧，这将成为我们创建购买的合约
and selling tokens in this tutorial and we'll continue building out this 在本教程中销售代币，我们将继续构建它
throughout the remainder of this series okay so the next thing we want to do is 在本系列的其余部分中还可以，所以我们接下来要做的是
create a second smart contract for the token alright so if you go 为令牌创建第二个智能合约
and revisit the diagram that I talked about earlier we have our website that 并重新访问我之前讨论的图表，我们有一个网站
talks to the blockchain and then you know the first smart contract is the 与区块链交谈，然后您知道第一个智能合约是
east swap smart contract that's what we just created here all right and the East swap智能合约这就是我们在这里刚刚创建的，
second smart contract is going to be the token that we buy and sell with ether 第二个智能合约将成为我们用以太币买卖的代币
right you know the native crypto currency of the etherium blockchain 你知道以太坊区块链的原生加密货币
right and that's the smart contract that we want to create right now so I'm gonna 是的，这就是我们现在要创建的智能合约，所以我要
go ahead and create a new file here so I'm just gonna reveal this here 继续在这里创建一个新文件，所以我要在这里显示
contracts youth swap all right look at a new file and here we'll say DAP token or 合同青年交换所有权利，看看一个新文件，在这里我们将说DAP令牌或
will say token token that's ole capital T okay en dot so this will be called DAP 会说令牌令牌是ole资本T okay en dot，所以将其称为DAP
token I'll show you how to do that here in a minute but this is going to be the 令牌，我将在稍后告诉您如何执行此操作，但这将是
file where we create the second smart contract for the crypto currency that 在文件中，我们为加密货币创建第二个智能合约，
we're gonna buy and sell so let me explain how this works a theorem allows 我们将要买卖，所以让我解释一下定理允许的工作原理
you to create your own cryptocurrency without creating your own blockchain 您无需创建自己的区块链即可创建自己的加密货币
which is really powerful it basically means you can write a smart 这真的很强大，它基本上意味着您可以编写一个聪明的
contract like this to govern or cryptocurrency all right with something 这样的合同可以管理或加密货币
called an e rc 20 token so you might have heard of that alright it's pretty 叫做e rc 20令牌，所以您可能听说过
popular if you go to a website like coin market capcom you can see a list of VAR 如果您访问硬币市场Capcom之类的网站很受欢迎，则可以看到VAR列表
c 20 tokens this is all the cryptocurrencies but on this list you'll c 20个令牌，这就是所有加密货币，但是在此列表中，您将
see let's see here tokens like maker is an e rc 20 token if you look at like 0x 看到让我们看看这里，像maker一样的令牌是e rc 20令牌，如果您看似0x
it's a near final you to a list of these but just note that you know you can just 这些清单几乎是最后一个，但请注意，您知道您可以
go to the homepage and see plenty of them there and if you look at any of 转到主页，在那里看到很多，如果您看任何
these ERC 20 tokens you'll just notice that they all have a lot in common 这些ERC 20代币，您会发现它们都有很多共同点
all right they all work the same way and actually if you go their smart contracts 好吧，他们全都以相同的方式工作，实际上，如果您遵循智能合约
you can look at the code and they all like I said they work the same way 您可以看一下代码，他们都像我说的那样，它们以相同的方式工作
basically they have like the same functions they have a transfer function 基本上，它们具有与传递函数相同的功能
they have an approved function alright a balance of and that's because a theorem 他们有一个已批准的函数很好的平衡，那是因为一个定理
tokens have to follow a standard alright called ERC 20 so ERC 20 is a standard 令牌必须遵循称为ERC 20的标准，因此ERC 20是标准
for a theory of tokens that just governs how they all work 代币理论只管它们如何运作
it specifies a set of functions and behavior that the tokens must implement 它指定令牌必须实现的一组功能和行为
in order to be supported on you know cryptocurrency exchanges to be held in 为了得到支持，您知道要在其中举行加密货币交易
wallets to be sent around it basically just creates you know a set of rules 围绕它发送的钱包基本上只会创建您知道的一组规则
that they must abide by so that are not you know constantly trying to reinvent 他们必须遵守，以便您不知道自己不断尝试重塑
the wheel with how they handle cryptocurrencies all right so you could 他们如何正确处理加密货币的方向盘，这样您就可以
read through the entire ERC twenty spec here if you wanted to but essentially 如果您愿意，请仔细阅读整个ERC的二十个规范
I'm gonna call it a few things you know Toki must have like a name you know 我要称呼它，你知道Toki必须像你知道的名字一样
symbol and some decimals okay so I'm gonna call it a few things here so for 符号和一些小数行，所以我在这里称它为
example the token must have a transfer a function this is what allows it to send 示例令牌必须具有传递函数，这就是它允许发送的功能
tokens and it also must have wants to hear an approved function and also like 令牌，并且它还必须要听到批准的功能，并且喜欢
a balance of function to get the current balance of whoever holds the soakin all 功能平衡，以获取持有所有浸泡物的人的当前平衡
right so it also supports things like name symbol and decimals which we'll see 对，因此它还支持名称符号和小数等内容，我们将看到
here in a minute so particularly in this tutorial we're gonna focus on the 稍后，特别是在本教程中，我们将专注于
balance of function and also the transfer function this is going to show 功能平衡以及传递函数将要显示
us how many depth opens we hold like this right you'll see the balance here 我们打开多少深度，我们就这样保持，您会在这里看到平衡
and then also the transfer function which is going to be used whenever we 然后还有传递函数，只要我们
sell the tokens in the eath swap contract so just notice that ye are c 20 卖掉伊顿掉期合约中的代币，所以只要注意你们是20
is a standard pretty much all CR c 20 tokens have to implement these types of 这是一个标准，几乎所有CR c 20令牌都必须实现这些类型的
functions so and because of this I don't want to reinvent the wheel and code out 功能如此，因此，我不想重新发明轮子并编写代码
a basic er C 20 tokens step-by-step right so we're gonna use this er C 20 基本的er C 20令牌逐步介绍，所以我们将使用此er C 20
token here I'll put a link down to this sorry I'll put a link for this down the 令牌在这里，我将为此提供链接，对不起，我将为此提供一个链接。
description below and we're just gonna copy and paste this code for the ERC 20 下面的说明，我们将复制并粘贴ERC 20的此代码
token inside of our project alright so if you want to learn to build this er C 标记在我们项目内部，所以如果您想学习构建此er C，
20 tokens step-by-step you can check out my full length tutorial code your own 您可以逐步获取20个令牌，可以自己查看我的完整教程代码
cryptocurrency on aetherium okay and this will show you how to build it 以太坊上的加密货币还可以，这将向您展示如何构建它
step-by-step right this is like an eight hour tutorial series but I don't want to 一步一步的权利，这就像一个八个小时的教程系列，但我不想
reinvent that you can follow that tutorial if you want to and for the sake 重新发明一下，如果您愿意并且为了自己的缘故，可以按照该教程进行操作
of you know getting started in this we're just going to copy and paste this 你们当中的人知道这是入门，我们将复制并粘贴
and put it in our project okay so don't worry we're gonna get plenty of practice 并把它放在我们的项目中，好吧，别担心我们会得到很多练习
coding solidity smart contracts and we build the eat swap exchange 编码坚固的智能合约，我们建立了吃掉交换
use this to save some time right so we'll go to our project and go to token 使用它可以节省一些时间，所以我们将转到我们的项目并转到令牌
dot Seoul and paste this in here and you can see all of the features of your FC 点首尔并将其粘贴到此处，您可以看到FC的所有功能
Twente tokens here like you know the amount the transfer function you have 这里有20个令牌，就像您知道传递函数的数量一样
balance of here all right and also the approved function all right 平衡这里的所有权利以及批准的功能
and again you don't have to know how all this code works basically just know this 再一次，您不必知道所有这些代码的工作原理
transfer function is what sends tokens from someone to another person the 转移功能是将令牌从某人发送到另一个人的功能
balance of function tells you how many tokens you have and then also the 功能平衡告诉您拥有多少令牌，然后
approved function you know let's somebody else you know spend your tokens 您知道的已批准功能让您认识的其他人花掉令牌
so we'll see these in action and you know if you want to learn more about how 因此我们将在实践中看到这些内容，如果您想进一步了解如何
this works go follow that other tutorial all right 这项工作可以按照其他教程进行
now let's finalize our setup and put this token on the blockchain too so 现在让我们完成设置，并将此令牌也放入区块链
let's go back to the deploy smart contracts or sorry deploy contracts file 让我们返回到部署智能合约，或者对不起部署合约文件
inside our migrations directory and what we're gonna do is put the token on the 在我们的迁移目录中，我们要做的就是将令牌放在
blockchain as well so I'm trying to copy this and paste it alright and we'll 区块链，所以我试图复制并粘贴它，我们将
change this to token I'll put it first and then just like this well say token 将其更改为令牌，我将其放在第一位，然后就像这样说得通
as well alright and then I'm gonna say deploy token alright and then a deploy 好的，然后我要说部署令牌，然后部署
eath swap okay so now let's put this on the blockchain as well so I'm going to Eath交换好了，所以现在我们也将其放在区块链上，以便
exit the trouble console like this say exit with a dot in front of it 像这样退出故障控制台，说在它前面有一个点退出
all right I'm gonna say truffle migrate and then whenever I do this I'm gonna go 好吧，我要说松露迁移，然后每当我这样做时，我都会去
- - reset alright so why is that well smart contract code is immutable alright -重置好吧，为什么好的智能合约代码是不变的呢？
it cannot change that's the whole point whenever you write the smart contract 每当您编写智能合约时，这都无法改变重点
code you put it on the blockchain you can't update it like you would a 您将其放在区块链上的代码无法像更新
normal application so the only thing you can really do is deploy a new copy of it 普通应用程序，因此您唯一能做的就是部署它的新副本
to the blockchain and that's exactly what this reset operation does so if I 到区块链，这正是重置操作的作用，如果我
said truffle migrate - - reset hit enter it's gonna put a new copy of the east 说松露迁移--重置命中输入它会放一个新的东方副本
swap exchange on the ganache blockchain and it's also going to put the token ganache区块链上的交换交换，并且还将放置令牌
alright so you can see that here you see your token and then you swap so 好吧，所以您可以看到在这里看到令牌，然后交换
now I'm gonna trouble console sorry truffle shuffle console and we'll say 现在我要麻烦控制台对不起松露洗牌控制台，我们会说
token equals a wait token got deployed 令牌等于已部署的等待令牌
nope sorry 不，谢谢
capital T token and then I can say balance equals a wait 大写T令牌，然后我可以说余额等于等待
token that balance of and then I'm gonna pass in the first account inside ganache 余额的令牌，然后我要在ganache中传递第一个帐户
here cutter paste this and balance alright and say balance your string all 在这里，铣刀将其粘贴并保持平衡，然后说平衡您的琴弦
right boom there we go so we can see here the first account inside ganache 我们去了右边的吊杆，所以我们可以在这里看到ganache的第一个帐户
has all of the tokens alright and I'll show you why that is so inside of the 拥有所有令牌，我将向您展示为什么在令牌内部如此
token file you can do this constructor function this is a function that gets 令牌文件，您可以执行以下构造函数该函数可以
run whenever the contract is put on the blockchain and basically what we do is 只要合同放在区块链上就运行，基本上我们要做的是
we take all the tokens and we assign them to the user that deployed the smart 我们获取所有令牌，并将它们分配给部署智能令牌的用户
contract okay and in this case that's the first account inside of ganache so 合同还可以，在这种情况下，这是ganache的第一个帐户，因此
you'll understand this more when we start explaining how smart contracts 当我们开始解释智能合约的原理时，您会更加理解
work and we code the other one out all right don't worry if this is confusing 工作，我们可以正确编码另一个代码，请不要担心这是否令人困惑
yet but essentially know that we took 1 million tokens that's how many this is 但实际上我们知道我们拿了100万个代币
and we assigned them to this account whenever we deployed the smart contract 并且每当我们部署智能合约时，我们便将他们分配给该帐户
to the blockchain ok so that's you know what we Illustrated here but that's 到区块链好了，那就是您知道我们在此说明的内容，但这就是
actually not right ok we don't necessarily want the user to have all 其实不对，好吧，我们不一定希望用户拥有全部
the tokens we want the eath swap exchange to have all the tokens because 我们希望Eath交换交换的令牌具有所有令牌，因为
we're gonna buy them and we want the E's swap contract to possess them so that we 我们要购买它们，我们希望E的掉期合约拥有它们，以便我们
can buy them from the actual smart contract ok so we want to do is transfer 可以从实际的智能合约中购买它们，所以我们要做的就是转移
all the tokens from this account to the east swap 从该账户到东部掉期的所有代币
exchange and we can do that and set our migration file like this okay so 交换，我们可以这样做并像这样设置我们的迁移文件，所以
basically we'll just say I will go fetch the token country like this Const token 基本上，我们只是说我将像这样的const令牌去获取令牌国家
equals oh wait token dot deployed just so we did in the console all right we'll 等于哦，等待令牌点部署完毕，以便我们在控制台中完成，我们将
do the same thing for each swap we'll say each swap and then each swap okay 为每个交换执行相同的操作，我们将说每个交换，然后每个交换都可以
so now we have a copy the token and a copy of the swap contract and we'll say 所以现在我们有了令牌的副本和交换合同的副本，我们将说
transfer all tokens to eat swap say 1 million and we'll do a weight token 转移所有代币以进行掉期交易，比如说一百万，我们将做一个权重代币
transfer each swap address and then we'll say we'll just go to the token 转移每个交换地址，然后我们说我们将转到令牌
copy the total supply put it here and we'll say yeah there we go that's all we 复制总供应量放在这里，我们会说是的，我们走了，仅此而已
need to do so if you look at the transfer function it just takes two 如果您看一下传递函数，则需要这样做，只需两个
arguments the address that you're sending it to in this case it's going to 在这种情况下，将参数发送到您要发送到的地址
be the eat swap smart contract and then the value which is the total number of 是饮食掉期智能合约，然后是价值的总数
tokens that you want to send in this case we just paste it in the total 在这种情况下您要发送的令牌，我们只需将其粘贴到总计中
supply which means we want to transfer all the tokens to the ESOP smart 供应，这意味着我们想将所有代币转移到ESOP smart
contract okay and just note that inside of this truffle project the account 签约好，只需要注意在松露项目中的帐户
that's performing all these actions is assumed to be the deployer or the first 假定执行所有这些操作的是部署者或第一个
account inside ganach like this okay so you can also see that the ether balance 像这样的帐户在ganach里面，所以您还可以看到以太币余额
has gone down as had this account that's because the deployer has paid the gas 像该帐户一样下降了，因为部署者已经支付了汽油费
fees to put the smart contract on the network okay so that basically means 将智能合约放在网络上的费用，这样基本上意味着
that anytime you do something on the etherium network you create a new 每当您在以太网络上做某事时，您都会创建一个新的
transaction you must pay for it with gas and that gas has been debited from this 交易，您必须用天然气支付，并且天然气已从中扣除
first account here okay so now we can open the truffle console 这里的第一个帐户好吧，现在我们可以打开松露控制台了
again actually sorry let's migrate it say truffle 再次抱歉，让我们迁移说松露
migrate - - reset this will put new smart contracts on the blockchain okay 迁移-重置这会将新的智能合约放到区块链上
let's make our changes oh so we had a problem here see here 让我们进行更改哦，所以我们在这里遇到问题，请看这里
away he's only valance I have an async function all right so let's change that 离开他是唯一的价位我有一个异步功能，所以让我们改变一下
we have to put the async keyword here a sink basically you can't use the await 我们必须将async关键字放在一个接收器中，基本上您不能使用await
keyword unless you're inside of an asynchronous function call all right so 关键字，除非您在异步函数调用内部，那么
we'll try that again shuffle my great - - reset and boom there we go so now we 我们会再次尝试洗牌，我的伟大-重新设置并开始繁荣，所以现在我们
came up with the trouble console all right now we can say eath swap equals a 现在想出了故障控制台，我们可以说Eath swap等于一个
wait 'if capital e got deployed oops sorry 等待'如果资金已经部署哎呀抱歉
call it as a function sorry typo here perfect 称之为函数抱歉，这里的错字很完美
if swap address boom and then now we want to say token equals a wait token 如果交换地址繁荣，那么现在我们要说令牌等于等待令牌
dot deployed all right and say token are say balance equals awaits balance of 点正确部署并说令牌是余额等于等待余额
toki swap dot address and what we should see here is that all of the tokens are toki交换点地址，我们在这里应该看到的是所有令牌都是
assigned to e swap okay all right moment of truth balance to string oh all right 分配给e交换好的，正确的瞬间，平衡到字符串哦
so it didn't work all right so I see why this was my fault 所以它不能正常工作，所以我明白为什么这是我的错
so we have to do if we're gonna do is an order you say oh wait yeah I forgot 所以我们要做的就是你说的命令哦，是的，我忘了
about this sorry everybody all right so wait deploy or dot deploy 关于这个对不起大家，所以请等待部署或点部署
token awaits token all right so let's try that again say exit and then truffle 令牌等待令牌正常，因此让我们再次尝试退出并松露
migrate - reset and actually I kind of like when I run into these errors on 迁移-重置，实际上，当我遇到这些错误时，我有点喜欢
screen because it shows you that you know even if I've done this a million 屏幕，因为它告诉您即使我已完成一百万次操作，您仍然知道
times I'm not perfect and then also it helps you debug problems that you're 有时我并不完美，那么它也可以帮助您调试自己遇到的问题
probably going to run into whenever you build your own blockchain applications 当您构建自己的区块链应用程序时，可能会遇到
all right so shut it again truffle console and we'll say eath swap 好吧，所以再次关闭它松露控制台，我们会说吃掉交换
equals wait actually we just copy and paste this I'll just do this make it 等于等待，实际上，我们只是复制并粘贴这个，我将这样做
faster and then we'll say you swap goes wait you slept up wood all right and 更快，然后我们会说您交换去，等您睡好了，
then we'll say tok balance oh wait token balance of beef swap or sorry 'the swap 那么我们会说tok balance哦，等牛肉交换的令牌余额，或者对不起'the swap
to address imbalance to string all right there we go boom all the tokens have 为了解决不平衡问题，我们在那里繁荣了所有代币
been transferred to the east swap contract and they're ready to be 被转移到东部掉期合约，他们准备好了
purchased all right so congratulations you come a really long way in this video 没事就买了，恭喜，您在这部影片中走了很长一段路
so far what we're gonna do next is actually program the e swap smart 到目前为止，我们接下来要做的实际上是对e swap智能编程
contract so that we can start purchasing tokens from it now that they're all 合约，这样我们就可以开始从中购买代币了
inside of the smart contract so we're gonna continue here focusing on this 在智能合约中，所以我们将继续专注于此
smart contract and building it out so specifically we're gonna create the buy 智能合约并进行构建，因此我们将专门创建购买
tokens functionality okay we're gonna allow people to purchase their tokens 令牌功能好吧，我们将允许人们购买其令牌
with ether all right the be able to go here enter 用乙醚没事就可以去这里输入
their aetherium amount and then receive you know a certain amount of tokens so 他们的以太币数量，然后收到您知道一定数量的代币，因此
we're gonna focus on the smart contract part of this not the interface just yet 我们将专注于智能合约部分，而不是界面
just the smart contracts so let's talk about how we're gonna do that all right 只是智能合约，所以让我们谈谈我们如何做到这一点
so one way of doing this would be to just you know create the functionality 因此，执行此操作的一种方法是仅知道创建功能
and then go to the truffle console and keep testing it out like we did it in 然后转到松露控制台并像我们一样继续进行测试
the last video but that's really slow and inefficient so what we want to do 最后一个视频，但这确实很慢而且效率很低，所以我们想做的是
instead is write tests that make sure that the smart contract works the way we 而是编写测试以确保智能合约以我们的方式工作
want to write so there's several reasons for this you know tests essentially they 想写，所以有很多原因，你知道测试他们
do just that they make sure that the code that you write works without having 这样做只是为了确保您编写的代码可以正常工作
to interact with it you know on a website or something like that more in 与您在网站或类似网站上了解的内容进行互动
the console and you can always keep running them and it just saves you a lot 控制台，您可以随时继续运行它们，这可以为您节省很多
of time and the other thing is it's really important to test smart contracts 时间长短，另一件事是测试智能合约真的很重要
before you with them on a blockchain and ensure 在与他们一起在区块链上之前，确保
that they work it's almost more important when you're developing 他们的工作原理在您开发时几乎更为重要
blockchain applications and other types of applications because you know smart 区块链应用程序和其他类型的应用程序，因为您很聪明
contracts can't really be changed and you want to make sure that they work 合同真的不能更改，您需要确保它们能正常工作
before you put them on a blockchain and the testing phase where you write 在将它们放到区块链和编写测试阶段之前
automated tests is critical for that development process right so shuffle 自动化测试对于该开发过程至关重要，因此请改组
lets us write tests like this we can basically just create a new directory 让我们编写这样的测试，我们基本上可以只创建一个新目录
all right inside of here we could say make derp it's a mkdir test all right so 好的，我们可以说make derp这是一个mkdir测试，所以
you can see a new folder was created here and this is where we'll create a 您会看到这里创建了一个新文件夹，这是我们将在其中创建一个
new file slight touch will see tests and we'll say eath swap is sorry test is 新文件略有接触将看到测试，我们会说Eath swap很抱歉，测试是
okay and then you'll see that a new file was created here all right so this is 好的，然后您会看到这里已经创建了一个新文件，所以这是
the file will write all the tests and we're gonna do it in JavaScript so yeah 该文件将编写所有测试，我们将使用JavaScript进行测试，所以
that's how truffle works essentially it gives us a way to write tests for 这就是松露的工作原理，它为我们提供了一种编写测试的方法
solidity smart contracts in JavaScript so yeah it's two different programming JavaScript中的solidity智能合约，是的，这是两种不同的编程
languages here you know this is solidity and then JavaScript is what we use to 这里的语言，您知道这是扎实的，然后JavaScript是我们用来
write the tests right so truffle comes pre bundled with a few different 正确编写测试，以便松露预先捆绑了一些不同的
libraries that are really going to help us out when we write tests the first is 当我们编写测试时，真正可以帮助我们的库是
the mocha framework this allows you to create test Suites in JavaScript and the mocha框架可让您使用JavaScript创建测试套件，
second one is the chai assertion library you can read more about these on their 第二个是chai断言库，您可以在其上阅读更多有关它们的信息。
websites basically chai allows you to compare things like you know saying a 网站基本上可以让您比较事物，例如您知道说
value should be a string or you know whatever the assertion is that is the 值应该是一个字符串，或者您知道什么断言就是
key word here that you want to focus on right so let's go ahead and create our 您想重点关注的关键字，让我们继续创建我们的关键字
tests so go to this file and we'll you know create a test like this we'll just 测试，请转到该文件，我们将创建一个这样的测试，我们只是
say contract all right and it'll paste it each swap and then we'll say accounts 说好合同，然后将其粘贴到每个掉期中，然后说账户
all right and then we'll pass in a callback function like this with an 好的，然后我们将这样的回调函数与
arrow and this is what will write all the tests inside of here all right 箭头，这就是将所有测试写入此处的内容
so in order to write tests against it we must first import the smart contract 因此，要针对它编写测试，我们必须首先导入智能合约
just like we did in our migrations file we can do the same way in the test suite 就像我们在迁移文件中所做的一样，我们可以在测试套件中执行相同的操作
so we'll just say token first all right so conce token with a capital T equals 所以我们先说令牌吧，所以让步令牌的大写字母T等于
artifacts require token and then contract you know II swap artifacts 工件需要令牌，然后收缩您知道的II交换工件
require you swap you can basically just copy and paste that directly from the 要求您交换，基本上可以直接从
migration file right here all right it's basically the same so now we have these 迁移文件在这里基本上是相同的，所以现在我们有了这些
inside the project or sorry inside the test suite the next thing we want to do 在项目中还是对不起，在测试套件中，我们要做的下一件事
is configure chai all right so that's the library I showed you a second ago 是配置chai好吧，那是我第二次向您展示的库
this is mocha and then this is chai so we'll configure the chai search in the 这是摩卡咖啡，然后是柴，因此我们将在
library like this you can just pull this from the master project on github or you 像这样的库，您可以从github上的主项目中提取它，或者
can you know code this out yourself so we say require chai and then we say use 你能自己知道代码吗，所以我们说要求柴，然后说使用
do chai as promised and then should okay so that's going to configure our 按照承诺去做柴，然后应该可以，这样就可以配置我们
assertions which will observe later when we write the tests right so the first 断言，稍后我们正确编写测试时将观察到，因此第一个
thing I want to do is just create a really basic test that ensure that the 我要做的就是创建一个真正的基本测试，以确保
smart contract was deployed to the network 智能合约已部署到网络
so first we'll say describe all right Heath swap deployment all right we'll 所以首先我们要说描述所有正确的Heath交换部署
say a sink and inside of here we'll create our first just like this 说一个水槽，在这里我们将像这样创建第一个水槽
we'll say it contract has a name and I know they doesn't really read quite like 我们会说合同有一个名字，我知道他们的读法不是很像
English but their works for now all right then we say cost name equals a 英语，但现在他们的作品还可以，那么我们说成本名称等于
weight you swap that name all right in order to do that we have to fetch it 权重交换该名称可以正确执行，我们必须获取它
just look at it in the console so this this code should look a lot like what we 只需在控制台中查看它，那么这段代码应该看起来很像我们
did in the console is essentially running that 在控制台中所做的实际上是在运行
that operation over and over and over again really easily inside the test 在测试中一遍又一遍地反复进行操作
that's why it's called an automated test so say eath swap equals o8 eath swap new 这就是为什么它被称为自动测试的原因，所以说eath swap等于o8 eath swap new
so not deploy but new all right and then finally we'll say assert equal house a 所以不要部署，而是新的，然后最后我们要说断言平等的房子
name let's say eath swap instant exchange all right remember this is what 名称，比方说，eath交换即时交换，好吧，记住这是什么
we observed in the console in the last video and essentially we're just 我们在上一个视频中在控制台中观察到，实际上，我们只是
checking for that inside the test so we can go to our terminal and run the test 检查测试中的内容，以便我们可以转到终端并运行测试
like this we say truffle tests I just make sure you have ganache running like 像这样，我们说松露测试，我只是确保您像
this oops sorry yeah like that right okay so we got a 抱歉，像这样，好吧，所以我们得到了
problem here says e swap is not defined so what we need to do is say let you 这里的问题是未定义e swap，所以我们需要说的是让您
swap sorry about that try like this and boom there we go our first test passed 交换对这种尝试感到抱歉，并繁荣发展，我们进行了首次测试
so that's how easy it is to get started testing smart contracts you know we just 所以这就是开始测试您知道的智能合约的难易程度
fetched the smart contract and performed the operation that we did in the console 获取智能合约并执行我们在控制台中执行的操作
in the last video like imagine how long it would take you to open up the console 在上一个视频中，想象一下打开控制台需要多长时间
and do that every single time you can do this command and it does it 并每一次都可以执行此命令
automatically for you and what we're gonna do in this tutorial series is you 自动为您服务，本教程系列中我们要做的是您
know create several more tests that would take us a really long time to 知道再创建一些测试将花费我们很长时间
check for in the console or maybe with the front-end application or something 检查控制台中的内容，或者检查前端应用程序或其他内容
like that so this saves a lot of time and gives you a lot of efficiency and 这样可以节省大量时间，并为您带来很多效率和
that's one really amazing thing about testing smart contracts so a lot of 关于测试智能合约，这真是一件了不起的事情
people do test-driven development and that's a really good practice I think 人们进行测试驱动的开发，这是一个非常好的实践
it's kind of challenging a lot of times for beginners so we're not exactly gonna 对于初学者来说，这是很多挑战，所以我们不会
be TDD so to speak in this video but we are gonna write tests we're gonna have 是TDD，所以要在本视频中发言，但我们要编写测试，
test coverage for the basic functionality of the contract itself 测试合同本身的基本功能
okay so now we can do is write test for the token as well all right so just like 好吧，现在我们可以做的是对令牌进行测试，就像
we described the eath slot deployment before that I'm gonna say describe token 我们之前描述了Eath插槽的部署，我要先说一下token
deployment all right and we'll say contract has a name and instead of east 部署好吧，我们会说合同有一个名字，而不是东
swap I will just say token right 交换我会说令牌正确
change both of these and we'll say token all right and in this case it won't be 更改这两个选项，我们会说令牌没问题，在这种情况下，它将不会
East swap it'll be DAP token and then we'll run the test like this all right I 东交换它将是DAP令牌，然后我们将像这样运行测试
said triple test and hopefully it'll pass 说三重测试，希望它将通过
all right there we go so the contract name is correct as well so the next 好的，我们去了，所以合同名称也正确，所以下一个
thing I want to do is make sure that the contract has tokens all right 我要做的是确保合同上有令牌
so remember we did that in the last video basically in the initial migration 所以请记住，我们在上一个视频中基本上是在初始迁移中做到的
this Miss migration sorry number two we transfer the tokens to the exchange to 此迁移小姐对不起，第二，我们将令牌转移到交易所
to e swap itself right and we checked in the console the the token balance for 交换自己的权利，我们在控制台中检查了令牌余额
east swap right so we want to run a test that makes sure that that's also correct 向东交换，所以我们要运行测试以确保这也是正确的
so we can do that like this we can say contract has tokens okay and we'll say 所以我们可以这样说，我们可以说合约有通证，我们会说
async I just hope you do before and inside of 异步，我只是希望你在之前和内部做
here let's just copy and paste this all right this and they'll also say token 在这里，我们只复制并粘贴此内容，他们也会说令牌
new all right so you swap new before that we'll say it soak in new all right 新没事，所以在您换新之前，我们会说它浸入新没事
and let's see here so essentially we want to do is transfer the balance just 让我们在这里看到，基本上，我们要做的就是转移余额
like we did here and the migration actually going to copy this all right do 就像我们在这里所做的那样，迁移实际上将复制此文件，
this all right and then say assert equal say balance or actually sorry before T 没关系，然后说相等，再说平衡，或者实际上在T之前感到抱歉
that lets check the balance say let balance equals a weight token that 让我们检查余额，说让余额等于重量令牌，
balance of all right then pass an e swap address all right and say assert equal 保留所有权利，然后再传递一个e交换地址，并说断言相等
balance to string and then what we want to do is you know just copy this value 平衡到字符串，然后我们要做的就是知道复制此值
and put it here 放在这里
oops sorry if I'm wrong place perfect all right so let's run that test 抱歉，如果我错了，那就好吧，让我们运行该测试
and see if that works 看看是否可行
hopefully everything was coated properly we're about to find out awesome perfect 希望一切都被适当地涂覆，我们将找到很棒的完美
so the contract has tokens okay so that's a really good basic test to start 所以合同上有令牌可以，所以这是一个很好的基础测试
off with you know everything is deployed properly everything that we created in 您知道所有内容都已正确部署，我们在其中创建的所有内容
the last video is covered in the test suite so before we continue let's do a 测试套件涵盖了最后一个视频，因此在继续之前，我们先做一个
little refactoring all right the first thing is some duplication so essentially 一点重构都没关系，第一件事就是重复，所以本质上
you know we're doing this twice you know token equals token dot new 你知道我们要这样做两次你知道令牌等于令牌点new
we're doing that here and we're doing that here but what we want to do is have 我们在这里做，我们在这里做，但是我们想要做的是
access to the token and every test without having to write this code over 无需编写此代码即可访问令牌和每个测试
and over and over again and we also want to perform this operation where we 一遍又一遍，我们也想执行此操作
transfer the tokens you know once so that we you know the rest of the tests 转移一次您知道的令牌，以便我们了解其余测试
work like that and then also the same for you know fetching the eath swap 像这样工作，然后对于您知道获取Eath交换也一样
contract so we can do is create something called a before hook like this 契约，所以我们可以做的就是创建一个叫做before hook的东西
so we say before I say async passing a function all right and we can just put 所以我们说在我说异步传递一个函数之前，我们可以把
all the code that would be here inside of here all right 这里所有的代码都可以
and say you swap and we can say just like this transfer all tokens to e swamp 并说您交换了，我们可以说就像这样将所有令牌转移到电子沼泽
all right and then we can take away all this all right and then we should go to 好的，然后我们可以带走所有这一切，然后我们应该转到
run the tests it should still work moment of truth okay boom we got a 运行测试，它应该仍然可以正常工作。
problem and actually I'm glad we ran into this 问题，实际上我很高兴我们遇到了这个问题
problem because this is an important thing to highlight I doesn't know what 问题，因为这很重要，要强调我不知道
token is and it doesn't know what swap is so there's a few different ways to 令牌是，它不知道什么是交换，因此有几种不同的方法
handle this squit saying when he gets here it 处理这个卑鄙的话，当他到达这里时
doesn't know I swap is and it doesn't know what token is that's because these 不知道我交换的是，也不知道是什么令牌，因为这些
variables are declared inside this there's a few different ways to handle 在其中声明变量，有几种不同的处理方式
this how I'm gonna do it is this say let token and then I can say let eath swap 这就是我要怎么做，这是说让令牌，然后我可以说让吃饭交换
alright but I can also do this in one line like this boom done and take these 好吧，但我也可以像这样的繁荣一样，一口气做到这一点，并接受这些
away and then now we have access to token and each swap inside these test 离开，然后我们就可以访问令牌和这些测试中的每个交换
examples so try it again hopefully I'll work this time and hit it awesome boom 实例，所以请再试一次，希望我这次能继续工作，并为之振奋
it passes all right so the last thing I want to do is refactor this number this 它顺利通过，所以我最后要做的就是重构这个数字
looks kind of funny right so I'll explain how this works you know this 看起来有点好笑，所以我将解释它的工作原理
might look confusing because this says this is a million tokens right that's 可能会令人困惑，因为这表示这是一百万个代币，
how many tokens exist but this number looks like a lot bigger than a million 存在多少代币，但这个数字看起来要比一百万个大得多
so let me explain why this token has 18 decimal places behind the zero okay so 所以让我解释一下为什么这个令牌在零后面有18个小数位
I'll show what that means if you go to source contracts token dot Seoul 我将展示如果您去采购合同令牌点首尔意味着什么
obviously decimals is 18 all right so what does that mean well basically like 显然小数点是18，所以这基本上意味着什么
when you're talking about currency I'll set the US dollar for example you know 当您谈论货币时，例如，您会设定美元
one dollar is often expressed like this all right one with a period or a decimal 一美元经常这样表示，可以带句号或小数
place and then two zeros ACTRA because you know a dollar has smaller 放置两个零ACTRA，因为您知道一美元要小
subdivisions called cents right and 100 cents equals a dollar so you know you 细分表示正确的分，而100分等于1美元，所以您知道您
can have fractional dollars like this dollar ninety-nine is almost two dollars 可以有分数美元，像这样的美元，九十九几乎是两美元
but it's 99 cents so whenever you're dealing with cryptocurrency and you know 但是这是99美分，所以每当您处理加密货币时，您就知道
aetherium smart contracts you don't really deal with decimals right aetherium智能合约，您实际上不会处理小数点
you basically have to express things as you know integers so you can't use 你基本上必须表达你所知道的整数，所以你不能使用
decimal places so if you're gonna write one dollar as an inside of an aetherium 小数点后的位，所以如果您要写一美元作为以太坊内部
contract you have to write 100 cents like this all right this is how you 合约，你必须像这样写100美分，好吧，这就是你的方式
would express one dollar inside of in aetherium smart contract but for ether 将在etherium智能合约中表示一美元，但表示以太币
you know the native cryptocurrency on the etherium blockchain and many 您知道以太坊区块链上的本机加密货币
tokens as well they use 18 decimal places behind the zero so you know one 令牌也使用零后面的18个小数位，所以您知道一个
aetherium or one ether might look like this and then do 1 2 3 4 5 6 7 8 9 10 11 醚或一种醚可能看起来像这样，然后做1 2 3 4 5 6 7 8 9 10 11
12 13 14 15 16 17 18 right 18 decimal places well that's what it looks like 12 13 14 15 16 17 18右18位小数正好是这样
all right and you can't use decimals so you have to take away the decimal place 好的，您不能使用小数，因此您必须删除小数位
and do everything in cents so to speak see E and T cents right like like cents 并以美分做所有事情
right but an ether you don't call it cents you call it way all right that's 是的，但是以太不叫分
the smallest aetherium value is called way so this is 最小的以太值称为方式，因此
like what one aetherium looks like in way value so similarly a lot of ERC 20 就像一个以太币看起来的价值一样，所以很多ERC 20
tokens use 18 decimal places just like ether does so we can use the same 令牌就像以太一样使用18个小数位，因此我们可以使用相同的
standard for our dap token that were created in this tutorial so it's going 本教程中为我们的dap令牌创建的标准
to have 18 decimal places behind it so that's what one DAP token would look 后面有18个小数位，所以这就是一个DAP令牌的样子
like here now if you want to talk about a million DAP tokens you put you know 像现在这样，如果您想谈论一百万个DAP令牌，您就知道了
three more zeros so you just do like 1 million 1 2 3 4 5 6 and then you would 再加上三个零，那么您就可以像一百万一样1 2 3 4 5 6
copy this and paste it here all right and you'll see that's the exact same 复制并粘贴到此处，您会看到完全一样
number boom done so that's a 1 million tokens looks like expressed in its 数字繁荣完成了，因此一百万个代币看起来像是
smallest subdivision like this all right it's actually important to understand 像这样的最小细分，了解它实际上很重要
because we're gonna use helpers in this tutorial series for aetherium I'll show 因为我们将在本系列教程中使用帮手来制作以太坊，我将展示
you we'll create our own right now so that we can make this a little more 您现在就可以创建自己的了，这样我们可以做得更多
human readable I would say function tokens in alright and what we're gonna 人类可读的，我会说功能令牌以及我们要做什么
do is convert this number from a human readable number like this 1 million to 要做的就是将这个数字从一个像100万这样的人类可读的数字转换成
this alright basically like this right we want a human readable function that 基本上像这样的权利，我们想要一个人类可读的功能，
does that so I'll do that right now we'll say tokens and we'll say return 这样做，所以我现在就做，我们说令牌，然后说返回
web 3 I'm sorry I will say new web 3 tills actually sorry Oh stupid first web web 3对不起，我要说新的web 3直到实际上对不起哦，愚蠢的第一个web
3 utils - way alright we'll say in that's the number of tokens they're 3个utils-好的，我们要说的是它们的令牌数量
going to pass in and then we'll say ether 要传递，然后我们说以太
alright so web 3 is a library that we use to talk to the blockchain we're 好吧，所以Web 3是我们用来与区块链对话的库
gonna see a web 3 use a lot more in this tutorial but essentially it has some 将在本教程中看到Web 3的使用更多，但本质上它有一些
utilities that allow us to convert aetherium or ether into way which I just 实用程序，使我们可以将醚或醚转换成我刚才所说的方式
talked about a minute ago where I showed you all those 18 decimal places and 在一分钟前谈到，我向您展示了所有这18个小数位，
stuff like that so we can use the exact same helpers for our token because it 这样的东西，所以我们可以为令牌使用完全相同的助手，因为它
has 18 decimal places behind it just like ether does all right so we're not 就像以太行事一样，它后面有18个小数位，所以我们不是
actually converting ether or actually converting our tokens to way at the 实际转换以太币或将我们的代币实际转换为
smart contract level or its smallest subdivision but that's what we can do 智能合约级别或其最小细分，但这就是我们可以做的
just like this okay so we're gonna use our helper and instead of you know 就像这样好吧，我们将使用我们的助手，而不是您知道
writing out this crazy long number will say tokens and then we'll pass in 1 写出这个疯狂的长数字会说令牌，然后我们将传递1
million one two three four five six and then we'll use it down here as well 百万一二三四有五六，然后我们也将在这里使用它
alright save it for the test again shuffle tests see if it works and there 好吧，再次保存它以供测试随机测试看看它是否有效
we go it passes awesome so we're gonna use this tokens helper so that we had to 我们通过它真棒，所以我们将使用此令牌助手，以便我们必须
write out those really long strings every time it's gonna make things a lot 每次写出那些很长的字串都会使事情变得很多
more readable and a lot easier okay alright so that sets up our test suite 可读性更高，更容易的方法好了，这样就可以设置我们的测试套件
now we can use this to start building out more the smart contract okay 现在我们可以用它来开始建立更多的智能合约了
so the next thing I want to do is actually talk about the rate so inside 所以我接下来要做的实际上是谈论价格
the smart contract the next thing we want to do is actually import the token 智能合约我们接下来要做的实际上是导入令牌
so that we can use it inside this smart contract you know essentially we're 这样我们就可以在您知道的智能合约中使用它
gonna talk to another smart contract from within this one the two are going 要从这两个中与另一个智能合约进行对话
to interact with one another so if we go back to our diagram 彼此互动，所以如果我们回到图上
you know the east swap exchange is actually going to talk to the DAP token 您知道东部掉期交易所实际上将与DAP令牌进行对话
smart contract so in order to do that we must import the DAP token contract into 智能合约，因此我们必须将DAP令牌合约导入
this particular file so we do that like this we do that with 这个特定的文件，所以我们这样做，我们这样做
solidity symport and then we say dot which is the current directory I'm sorry solidity symport，然后我们说点对不起，这是当前目录
I'm gonna say token Sol alright cuz that's the same token file that we see 我要说令牌Sol好吧，因为它与我们看到的令牌文件相同
here so you swap and then token we're just importing token like this so 在这里，您先交换令牌，然后再交换令牌，就像这样导入令牌
really quickly we can just run our tests oh and also we don't have to I had from 很快我们就可以运行测试了哦，而且我们也不必
the test we can just do truffle compile to see if that worked all right so 测试我们可以进行松露编译以查看是否正常
truffle compile is just a command that makes sure that the code has no syntax 松露编译只是确保代码没有语法的命令
errors alright so that works we don't actually have to go through the process 错误就可以了，这样我们实际上就不必经历整个过程
of running the entire test suite just to see if our code is working properly and 运行整个测试套件只是为了查看我们的代码是否正常工作，以及
you'll notice that truffle compile gets run before the test suite even runs so 您会注意到在测试套件运行之前就已经运行了松露编译，因此
it's kind of just a first line of defense to make sure that everything 这只是确保所有事情的第一道防线
worked okay so we talkin and then next we want to do is keep track of the token 工作正常，所以我们进行交谈，接下来我们要做的是跟踪令牌
and the smart contract like this say token capital T okay n say public token 像这样的智能合约说令牌资本T好吧n说公共令牌
and what this does is it creates a variable that represents the token smart 它所做的是创建一个代表智能令牌的变量
contract and you know later when we purchase tokens in this tutorial you 合同，您以后会知道，当我们在本教程中购买代币时，您
know we'll be able to call the token methods on this variable 知道我们将能够在此变量上调用令牌方法
you know like transfer for example that's what's going to happen whenever 你知道像转移这样的事情，每当发生这种情况时
we purchased tokens we want to call this function and we need to have access to 我们购买了代币，我们想调用此函数，我们需要访问
it alright so we'll just likes a token transfer and we'll use this particular 没关系，所以我们只喜欢令牌转移，我们将使用此特殊
variable to do that alright so next what we need to do is tell this smart 变量来执行此操作，所以接下来我们需要告诉这个聪明的人
contract where this particular contract is located so we're going to do is 该特定合同所在的合同，所以我们要做的是
create a function that gets run whenever the smart contracts are deploy to the 创建一个将智能合约部署到
network call it constructor and say public and inside of here we're gonna 网络将其称为构造函数，并说“ public”，在这里
basically set the token up so when we say token like this when we import the 基本上设置了令牌，所以当我们导入
smart contract it's just the code for the smart contract it doesn't actually 智能合约这只是智能合约的代码，实际上并没有
tell us where it is on the blockchain all right so remember like when we do 告诉我们区块链上的位置，所以请记住
the truffle console we saw that the token 在松露控制台上，我们看到了令牌
an address just like the counts do like the smart contracts will have addresses 就像计数一样，智能合约会有地址
that look like this well we also need that to use the smart contract inside of 看起来很好，我们还需要在其中使用智能合约
here we need the code for the smart contract and then the address okay so 在这里，我们需要智能合约的代码，然后需要地址，所以
what we can do is pass the smart passed the address in whenever we deploy the 我们能做的就是每当我们部署
token to the network so because I token and say token tok in alright and then 令牌网络，所以因为我令牌并说令牌令牌好
say token equals underscore token all right so I use underscores here as a 说令牌可以等于下划线令牌，所以我在这里使用下划线作为
naming convention and it also helps conflict from this right here all right 命名约定，这也有助于从这里权利冲突
so that gives us a token that we can actually interact with later inside of 这样就给了我们一个令牌，以后我们可以与之交互
here all right so also let me stop and 好的，还让我停下来，
explain a couple more things first is how these variables work so this right 首先解释几件事是这些变量的工作原理
here is called a state variable name is a state variable because the data that's 这里称为状态变量的名称是状态变量，因为
stored in the name variable is actually stored on the blockchain that's why we 存储在名称变量中实际上存储在区块链上，这就是我们
were able to go to the console and also the tests and fetch the variable name 能够去控制台，也去测试并获取变量名
value for name right so in the same way we want to store the token on the 正确的名称值，因此我们希望将令牌存储在
blockchain but this right here this is just a local variable all right it's 区块链，但是这里只是一个局部变量
actually a function argument that we access with the local variable here and 实际上是我们在此处使用局部变量访问的函数参数
this doesn't get store to the blockchain unless we do this all right so that's 除非我们一切正常，否则这不会存储到区块链中
why we assign token right here okay so this is just a variable that we could do 为什么我们在这里分配令牌好，所以这只是我们可以做的变量
other stuff with and our function will see that more later but this actually 其他的东西和我们的功能将在以后看到更多，但这实际上
writes to the blockchain because it stores it to this state variable okay so 写入区块链，因为它将其存储到此状态变量中，所以
we'll see other properties of state variables like for example they can be 我们将看到状态变量的其他属性，例如它们可以是
accessed in other functions where this variable right here can only be accessed 在其他函数中访问，此处只能访问此变量
inside of this particular function right and again this constructor function this 在此特定函数的内部，此构造函数再次
is a special function with the constructor keyword inside solidity that 是在solidity中具有constructor关键字的特殊功能，
gets one once and only once whenever this contract gets deployed to 只要将此合同部署到
the blockchain we can't like call this function for example inside the test 我们不喜欢在测试内部例如调用此函数的区块链
right because we added an argument here we have to do a couple things 对，因为我们在这里添加了一个论点，我们必须做几件事
all right first we have to update the migrations whenever we deploy the token 好吧，每当我们部署令牌时，我们都必须更新迁移
to the blockchain so if we go to initial migrations or sorry I deploy contracts 到区块链，所以如果我们进行初始迁移或对不起，我会部署合同
we have to tell the token address all right that's all we did this first so 我们必须告诉令牌地址正确，这就是我们首先要做的所有事情，因此
what we do is pass in the argument for this constructor function right here 我们要做的是在此处传递此构造函数的参数
token with token address like this say token address all right so let's try to 令牌这样的令牌地址说令牌地址没问题，所以我们尝试
migrate the contracts again truffle migrate - - reset remember we need to 再次迁移合同松露迁移--重置请记住我们需要
employ a new copy to the blockchain all right it worked so the next thing we 可以使用新副本到区块链，所以接下来我们
need to do is go to the tests and we want to pass in the token address there 需要做的是去测试，我们要在这里传递令牌地址
as well all right so essentially what we do is just modify what we have already 好吧，所以基本上我们要做的就是修改我们已经拥有的
right we just go here you swap and say token address all right and that makes 好吧，我们就到这里，您交换一下，说令牌地址没问题，这使得
the eath swap contract oops sorry nothing jump test that makes the e swap Eath交换合同哎呀，没有任何使e交换的跳转测试
contract aware of the token inside the test as well it provides the necessary 合同也知道测试中的令牌，它提供了必要的
constructor argument that we need to move forward okay so let's keep building 构造函数参数，我们需要继续前进，所以让我们继续构建
this out much the test pass first yeah oh good the next thing I want to do is 首先要通过这个测试，是的，好，接下来我想做的是
you know go ahead and create a way to buy the tokens so we'll create a new 您知道继续创建一种购买代币的方法，因此我们将创建一个新的
function inside the smart contract like this we'll just call it by tokens let's 像这样在智能合约中发挥作用，我们只用代币来称呼它，
say function all right I'll give it a name say buy tokens and we'll do these 说功能好吧，我给它起个名字，说买代币，我们来做
parenthesis like this and this is where we're gonna write all the code to 这样的括号，这就是我们要编写所有代码的地方
purchase the tokens so inside of here what we want to do is essentially just 购买代币，所以在这里我们要做的基本上就是
transfer tokens from the eath swap contract to the person who's buying them 将代币从食堂掉期合约转移到购买者
all right so we're going to rely upon the transfer function write this 好的，所以我们将依靠传递函数来编写
function in here from the token and we just call it like this we basically just 从令牌在这里起作用，我们就这样称呼它，基本上
say token dot transfer 说令牌点转移
and then that will send the tokens from the token contracts are the ESOP 然后将从令牌合约中发送令牌的是ESOP
contract to the person who is purchasing them all right whoever's calling this 与购买他们的人签定合同
function we need to pass in a few arguments we need to tell it who it's 函数，我们需要传递一些参数，我们需要告诉它是谁
going to and then also the value okay so how do we determine that 然后再确定值，那么我们如何确定
well the recipient is going to be the person who calls this function all right 那么接收者将是可以调用此功能的人
and inside of solidity we can find out who that is like this you say MSG sender 在稳固性的内部，我们可以找出您所说的味精发送者
so let me explain that MSG or message is a global variable inside of solidity and 因此，让我解释一下，味精或消息是坚固性内部的全局变量，
sender is the value of the address that's calling this function so you know sender是调用此函数的地址的值，因此您知道
for example something like this okay so that's the first argument you know who 例如这样的事情，所以这是你知道谁的第一个论点
the tokens are going to and then next we want to determine the value so could say 令牌将要去，然后下一步我们要确定值，所以可以说
like you know one token followed by you know 18 decimal places yadda yadda yadda 就像您知道一个令牌，然后知道小数点后18位yadda yadda yadda
but we actually want to calculate this value out all right so how do we do that 但是我们实际上是想完全计算出该值，所以我们该怎么做
well we know that we're sending in etherium or ether you know the 好吧，我们知道我们正在发送以太或以太，您知道
cryptocurrency on the etherium blockchain in order purchase tokens if 如果购买代币，则以太坊区块链上的加密货币
we go back to our finished application that's what we do we buy the tokens here 我们回到完成的应用程序，这就是我们要做的，我们在这里购买代币
with ether all right so that's what's gonna happen is the person calling this 用乙醚没事的，那会发生的是那个叫这个人的人
function is gonna be sending in ether and they're gonna buy tokens so we want 功能将发送以太币，他们将购买代币，所以我们想要
to do is determine how many tokens they purchase based upon the etherium amount 要做的就是根据以太币数量确定购买了多少代币
that they're sending whenever they call this function alright so if you go to 他们只要调用此函数就可以发送，因此如果您转到
our finished app here we see that one aetherium equals 100 在这里完成的应用程序中，我们看到一个以太等于100
you know DAP tokens so we have to perform this calculation alright so what 您知道DAP令牌，所以我们必须执行此计算，所以
we're going to do is just create a number variable here called token amount 我们要做的就是在这里创建一个数字变量，称为代币数量
all right we'll make a calculation so the token amount it's gonna look like 好吧，我们将进行计算，因此代币数量将看起来像
this we can just say you int so this is going to stand for an integer an 我们可以说你int所以这将代表一个整数
unsigned integer it's a token amount amount all right it's gonna equal you 无符号整数，它等于代币数量，等于你
know something so what's it going to equal 知道一些东西，这等于什么
well basically we want to do is say you know amount of theorem you know 好吧，基本上我们想做的是说你知道定理的数量
multiplied by the redemption rate okay so all right so the redemption rate 乘以赎回率就好了，好吧，赎回率
equals you know number of tokens they receive for one ether all right in this 等于您知道他们在一个醚中收到的代币数量
case that's going to be 100 right so if you go back here you say 1/8 equals 100 情况就是100，所以如果你回到这里，你说1/8等于100
dap so we're gonna do is create a state variable inside of here called rate say dap，所以我们要做的是在此处创建一个称为rate的状态变量
you int public right all right and we're actually going to assign the value right 您拥有公共权利，我们实际上将分配价值权利
here in line call it 100 all right so I'll pause liquid clean also say this u 在这里称它为100好吧，所以我暂停液体清洁也要说这个
n stands for unsigned integer okay which basically means you know 100 is an n代表无符号整数，这基本上意味着您知道100是一个
integer it can't have decimal places and unsigned means that it can't be negative 整数，不能有小数位，无符号表示不能为负
all right means it can't have a sign in front of it like this okay okay so same 好吧，这意味着它前面不能有标识，就像这样
for this UN token amount has to be a positive integer all right so here's a 这个联合国令牌的数量必须是一个正整数，好吧，这是
Redemption rate the number of tokens they receive for one ather that's going 赎回率他们将获得的另一枚代币的代币数量
to be the rate all right and then what we're going to do is find the amount of 成为正确的汇率，然后我们要做的就是找到
aetherium and multiply it by the redemption rate so how do we find the 醚，然后乘以赎回率，那么我们如何找到
amount of aetherium or ether just like m/s you got sender we can do it like 像您发送者所发送的m / s一样数量的乙醚或乙醚，我们可以像
this MSG value alright so what that does is it is another global variable that 这个MSG值没问题，所以它是另一个全局变量
tells us how much ether was sent whenever this function was called all 告诉我们每当调用此函数时，发送了多少以太
right so it's a special reserved keyword inside of solidity but this is gonna 对，所以这是Solidity中的一个特殊保留关键字，但这会
tell us how much ether was sent whenever the function was called 告诉我们每当调用函数时发送了多少以太
so we just take that value and just multiply it by the right all right so 所以我们只取那个值，然后乘以正确的值
it's pretty straightforward once you understand the basic concepts okay so 一旦了解了基本概念就非常简单了
now we can say calculate the number of tokens to buy let me take 现在我们可以说计算要购买的代币数量
this out take this out take this out so quick recap 这个拿出来这个拿出来这样快速回顾
we're just catch them a token amount or taking the etherium amount multiplying 我们只是抓住他们一个象征性的数量或以太坊数量相乘
it by the rate the number of tokens when they get when they contribute one ether 用代币贡献一个醚时获得的代币数量的比率来表示
and then we call the tokens transfer function we say msg sender that's who 然后我们调用令牌传递函数，我们说味精发送者
we're sending it to the person who's calling it and then we're passing in the 我们将其发送给调用它的人，然后我们将
token amount which we calculated here right so we see that two in value and 我们在这里计算出的代币数量，所以我们看到两个值和
that's two and value all right so the last thing we need to do to this 那是两个，很珍惜，所以我们要做的最后一件事
function before we can try it out is make it public so that it can be called 我们可以尝试之前的功能是将其公开，以便可以调用它
outside the smart contract and then the next thing we need to do is make it 在智能合约之外，接下来我们需要做的是
payable all right and that's gonna allow us to send aetherium whenever we call 应付的所有权利，这将使我们能够在每次致电时发送以太币
this function right so if we didn't have this we wouldn't be able to send ether 这个功能正确，所以如果我们没有这个功能，我们将无法发送以太币
whenever we do it okay so there's give me a little bit more to this but that's 只要我们这样做就可以了，所以可以给我更多一点，但这就是
the basic functionality for now and we can run a test against it so let's just 现在是基本功能，我们可以对其进行测试，让我们
try to compile the smart contract first truffula compile see if this works and 尝试先编译智能合约，然后再编译，看看是否可行，并且
if it does we'll continue on with the tests all right that worked so let's 如果可以的话，我们将继续进行所有可行的测试，让我们
write the basic test for that functionality and we'll say describe so 为该功能编写基本测试，我们将描述为
we'll minimize this and say describe I might get myself some space here 我们将其降到最低并说描述我可能会在这里留一些空间
say by tokens we're gonna write all the tests for this function here say async 用令牌说，我们要在这里编写该功能的所有测试
alright and we'll say it's allows user to instantly purchase tokens for us are 好了，我们会说它允许用户立即为我们购买代币
from eath swap for a fixed price say sync alright so inside of here we want 从伊斯坦交换固定价格说同步好吧，所以在这里我们想要
to do is basically just say you know each swap by tokens alright and then we 要做的基本上是说您知道每个交换都由令牌完成，然后我们
want to pass in the person who's purchasing them so how we do that is 想要传递购买者的信息，那么我们该怎么做
basically tell a specific account so you can see this accounts array here like I 基本上告诉一个特定的帐户，所以您可以像我一样在这里看到此帐户数组
say it counts 1 is it from accounts 1 and then what we also need to do is not 说它计数为1是来自帐户1的计数，然后我们还需要做的不是
just tell who it's who's calling the function but we also want to say how 只是告诉谁是谁在调用函数，但我们也想说一下
much ether that they're sending whenever they purchase the tokens as well ok so 他们在购买代币时会发送的大量以太币也可以
we do that with value alright and let's say what they want to contribute 1 ether 我们做到了价值就好，让我们说他们想贡献1个以太币
so we tell it 1 ether you know followed by 18 decimal places 1 2 3 4 5 6 7 8 9 所以我们告诉它您知道的1个以太币，后跟18个小数位1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 remember we can't use decimal places so we have to 10 11 12 13 14 15 16 17 18记住我们不能使用小数位，所以我们必须
create a value like this but that would be the basic that'd be the basic 创建这样的值，但这将是基本的
functionality we can just say a weight youth swap by tokens so that's not going 功能，我们可以说是通过令牌交换一个体重青年，所以这不会
to check for anything but let's just see if it works just make sure nothing broke 检查是否有任何东西，但让我们看看它是否有效，只是确保没有任何损坏
yet alright so by Duncan is not a function I'll see her 还好，所以邓肯不是我要见她的职务
alright so looks like I had a little error let's go back to our code here 好吧，看来我有点错误，让我们回到这里的代码
capitalize the T that's my fall everybody buy tokens should be have it 大写T是我的秋天，每个人都应该购买代币
have a capital T let's go back here all good let's try it again 有大写字母T让我们回到这里，一切顺利，让我们再试一次
trouble tests let's see if it works and boom there we go so it doesn't actually 故障测试让我们看一下它是否有效，然后我们就开始繁荣了，所以实际上没有
check for anything yet I just want to make sure that this was configured 检查是否有任何东西，我只想确保已配置好
properly so let's refactor this before I move on instead of you know coding this 正确，所以让我们在继续之前进行重构，而不是您知道编码
out long form we're going to use utility we're not going to use tokens like this 长的形式，我们将使用实用程序，我们将不使用这样的令牌
we're gonna say say this alright let's try it again 我们要说可以，让我们再试一次
remember tokens work like that but we're gonna say to way from ether because 记住代币是这样工作的，但是我们要对以太说远，因为
we're sending an ether here also in sorry hit hit want to do one either 我们也在这里发送以太
alright and the next thing we want to do is refactor this accounts that we're not 好的，接下来我们要做的是重构该帐户，而不是
always like reading out of this array so we're gonna use two users in this case 总是喜欢读取此数组，因此在这种情况下，我们将使用两个用户
alright and you can actually break this out inside the test suite instead of 好吧，您实际上可以在测试套件中进行扩展，而不是
returning an array here inside this callback function we can actually fetch 在此回调函数内返回一个数组，我们实际上可以获取
accounts out individually by declaring an array and say accounts or sorry we 通过声明一个数组并说出帐户来对账，或者对不起我们
say deployer that's the first account and then investor 说部署者是第一个帐户，然后是投资者
okay so deployer is gonna reference the first account inside ganach like this 好的，因此部署者将像这样引用ganach中的第一个帐户
alright that you know you can see their balance keeps going down and then the 好吧，您知道您可以看到他们的余额持续下降，然后
second account will be the investor okay we can see their balance has also gone 第二个账户将是投资者，好的，我们可以看到他们的余额也消失了
down because they just called the buy tokens function so they actually went 下降，因为他们只是调用了购买令牌功能，所以他们实际上去了
down by one ether each time we ran it so now we say investor here on the test see 每次运行它时都会掉一个醚，所以现在我们说测试中的投资者看到了
if it still works 如果仍然有效
well there we go all right so the next thing is to explain you know from a new 好吧，我们一切顺利，所以接下来的事情是解释您从新
value so this from here is gonna correspond to msg sender all right we 值，所以从这里开始，这将对应于味精发送者，好吧，我们
specify the address and then the value here is gonna represent let's see here 指定地址，然后这里的值将代表我们在这里看到
we go 我们去
the MSG got value okay so this corresponds to from and this 味精的值还可以，所以这对应于from和this
corresponds to value just like this I'm gonna take this away all right so now 对应于价值，就像这样，我要把它拿走，所以现在
before we continue on with this specific example let's refactor this into a 在继续执行此特定示例之前，让我们将其重构为
before hook just like this so inside of here this say before okay and we're 像这样钩之前，所以在这里面说，好吧，我们
gonna move this inside of there all right and we're to say results and we're 要把它移到里面，我们要说结果，我们
gonna say let results okay and we'll say purchase tokens 要说结果还可以，我们会说购买代币
before each example and so inside of here what we want to do is just check 在每个示例之前，所以在这里我们要做的就是检查
that the balance actually changed so we're gonna check that the investor 余额实际上发生了变化，所以我们要检查投资者
received the tokens so let's say Wester received tokens after purchase all right 收到了代币，所以说韦斯特在购买后就收到了代币
and we can just check for the investor balance like this we just say you know 我们可以像这样检查投资者余额，我们只是说你知道
let Bester balance equals weight token balance of and say investor and then we 让Bester余额等于权重令牌余额，然后说投资者，然后我们
check it say assert equal investor balance 检查并说保持投资者平衡
two string tokens 100 so let's try that 两个字符串标记100，让我们尝试一下
see if it works 看看是否有效
boom there we go awesome so that's the basic functionality so the next thing we 我们在那里很棒，这是基本功能，所以接下来我们
want to do is check the east swap balance we're gonna make sure that you 要做的是检查东部掉期余额，我们将确保您
know it lost tokens it lost 100 tokens so like this let's just say you know let 知道它失去了代币它失去了100个代币所以我们只说您知道让
eath swap balance will say check each swap balance after purchase and we'll Eath掉期余额会说购买后检查每个掉期余额，我们会
say eath swap balance equals a wait token balance of all right passing an e 说Eath交换余额等于通过e的所有权利的等待令牌余额
swap address all right and then we'll check it will say asserts equal eath 交换地址没事，然后我们检查它是否会说断言等同
swab balance to string and then pass in tokens and then the number of tokens 拭子余额转换为字符串，然后传递令牌，然后传递令牌数量
should be that many once we subtract a hundred and then say 一旦我们减去一百然后说应该是那么多
yeah there we go should work let's try the test see if it passes 是的，我们应该继续进行测试，看看测试是否通过
boom boom there we go each swipe balance to string us on a function so see your 我们要通过每个滑动平衡将功能串起来，所以请参阅
East fob balance okay I see the problem here I just missed them in all right 东离岸价平衡好吧，我在这里看到问题了，我只是很想念他们
save that try it again so sorry I'm full of typos today everybody yeah all right 保存，然后再试一次，对不起，今天我有很多错别字，大家都很好
boom there we go so the next thing I want to do is check that the ether 繁荣，我们去了，所以我下一步要做的就是检查以太
balance went up so we could do that like this we can say eath swap balance equals 余额上升，所以我们可以这样操作，可以说Eath交换余额等于
oh wait web three eath get balance this is the function that we use to check the 哦，等待网络三吃平衡，这是我们用来检查
etherium bounce eath swap balance all right we can say assert equal eath swap 以太弹跳吞噬交换平衡可以说断言等于吞噬交换
balance to string and we can say web 3 you 平衡到字符串，我们可以说网络3
Dill's to weigh one either let's also do that see if it works okay 莳萝称重之一，让我们也这样做，看看是否还可以
we got a problem here I just missed typed this you swap address sorry 我们在这里遇到问题，我只是错过了输入此内容，而您交换地址对不起
everybody let's try it again hopefully this will 大家让我们再试一次，希望这会
fix it see if it passes all right there we go 修复它，看看它是否顺利通过
works so we can see that the token bounds went down and the eath swap 可以正常工作，因此我们可以看到令牌边界下降并且Eath交换
exchange received one ether all right so the ether left the you know users 交易所收到了一个以太币，所以以太币离开了，您知道的用户
account the investor's account and went to east swap and the investor got tokens 账户投资者的账户并去往东掉期，投资者获得代币
all right and then the token balance for the ESOP exchange went down just like we 没问题，然后ESOP交易所的代币余额下降，就像我们
expect right in our finished application the investor goes here and basically 期望在我们完成的申请中，投资者基本上会来到这里
they just put in one ether and they got 100 tokens and click swap the exchange 他们只放入一个以太币，他们得到了100个代币，然后点击交换交易所
or each swap in this case gets one ether and they dispense 100 tokens and the 或在这种情况下，每次交换都会得到1个以太币，然后分配100个代币，
token balance goes down while we're here I want to do one more thing I want to 当我们在这里时，代币余额下降了，我想再做一件事
teach you about events inside of solidity aetherium allows you to emit 教您有关固体内的事件的了解
events from your smart contracts essentially they're a way of subscribing 智能合约中的事件本质上是一种订阅方式
to events in the blockchain and finding out that something happened so this case 处理区块链中的事件，并发现发生了什么事情，所以这种情况
what we want to do is trigger an event 我们要做的是触发一个事件
that tokens were purchased all right so say emit and events so basically we want 可以正确购买代币，例如说发射和事件，基本上我们想要
people to subscribe to this and say oh you know a token was purchased and it's 人们订阅它并说哦，您知道已经购买了代币，
going to allow them to do lots of things we'll be able to inspect the value of 允许他们做很多事情，我们将能够检查
how many tokens were purchased and things like that it'll show you in the 购买了多少代币，类似的东西会在
test ok so we do like this first we needed to 测试确定，所以我们首先喜欢这样，我们需要
define an event it's pretty easy we can just do it at the top of my file like 定义一个事件很容易，我们可以像在文件顶部那样
this we say event token purchased all right 这就是说我们购买了事件令牌
now to add a semicolon like that and we can add some arguments to the event we 现在添加这样的分号，我们可以向事件添加一些参数
say address count that's going to be who is calling 说出将要呼叫的地址数
the function you know who purchased the tokens address token of the token that 您知道谁购买了令牌的功能地址令牌的地址令牌
was purchased will say units amount the amount of tokens that were purchased and 购买后会说单位数量购买的代币数量，
then you nth rate you know the redemption rate that they purchased the 那么您就知道他们购买的赎回率
tokens with so basically someone if they had all this information could you know 基本上拥有某人的令牌，如果他们拥有所有这些信息，您会知道吗
make like a transaction history or something like that and determine the 进行交易历史记录之类的操作并确定
exact amount that was purchased and all that kind of stuff and how much ether 购买的确切数量以及所有此类物品以及多少乙醚
they send so that's that's why you Justin like that so it's really easy to 他们发送，所以这就是为什么你贾斯汀那样，所以真的很容易
omit the event inside of the function we just say emits token purchased all right 忽略函数内部的事件，我们刚刚说过，它会发出购买的令牌
and so the account is gonna be MSG dot cinder all right just like we did here 就像我们在这里所做的那样，该帐户将成为MSG点炭渣
and then the address as me the token all right for the token right here but we 然后是我的地址，令牌就可以在这里使用令牌，但是我们
must convert this to an address like this okay and then the next thing is 必须将其转换为这样的地址，然后下一步是
going to be the amount it's just token amount just copy this 将会是象征性的数量，只需将其复制
and paste it here and then finally the rate is going to be the rate they 并粘贴到这里，然后最终速率将是它们的速率
purchased it with here all right and then we'll just do a semicolon at the 可以在这里购买它，然后我们将在
end of the line so let's just run the test again make sure they didn't break 行的结尾，所以让我们再次运行测试，确保它们没有中断
anything all right should work just fine all right it passed perfect so now we 没事的就可以了，没事的吧，它过去了，所以现在
want to do is actually inspect this event inside the test to make sure that 要做的是实际上在测试中检查此事件以确保
it you know returned the arguments we expect so what we can do is go back here 如果您知道返回了我们期望的参数，那么我们可以做的就是回到这里
and inspect the event like this I'm just going to log into the console first so 并检查这样的事件，我将首先登录到控制台
that you see how we find it essentially we're going to use this result that was 您将看到我们如何找到它，基本上我们将使用该结果
returned after we you know called the function and we'll just say Const event 在您知道调用该函数之后返回的，我们只会说Const事件
I'll just say this console log and we'll say results that logs all right this is 我只说这个控制台日志，我们说的结果可以记录下来，这是
the laws that come back from the function call we run the test again to 从函数调用返回的定律，我们再次运行测试以
see what that is it'll just show it here on the screen when the tests finish will 看看它是什么，只要测试完成，它就会在屏幕上显示出来
be able to see what that looks like since we did a console log right boom 能够看到外观，因为我们进行了控制台日志右转
there you go so this is what the log looks like so 你去那里，所以这就是日志的样子
it's got a bunch of different properties here's got like the you know ID the 它有很多不同的属性，就像您知道的ID
address all that kind of stuff but if you look at the args and then the result 解决所有这类问题，但如果您查看args，然后再看结果
you can see these values account token amount and rate which we defined inside 您可以看到我们在其中定义的这些值，帐户令牌数量和费率
the event so the event gives us you know some history of the data that was sent 事件，因此事件使我们知道发送的数据的一些历史记录
in with the function and that's one of the reasons we do this all right so we 与功能，这就是我们可以做到这一点的原因之一，所以我们
can write a test to make sure these values are right we just dig into this 可以编写测试以确保这些值正确，我们只需要对此进行深入研究
object by saying you know result logs all to get the first one so say zero and 通过说您知道结果记录所有对象来获取第一个对象，因此说零，然后
then dards all right so let's run the test again 然后好一点，让我们再次运行测试
see what those are that should just give us this set of values here all right 看看这些应该给我们这套价值观带来什么
boom so now we can call a count token amount and rate on this directly so say 繁荣，因此现在我们可以直接对此调用计数令牌的数量和费率
say Const event equals this right what just showed you say assert equal I'm 说Const事件等于这个权利，刚刚表明您说断言等于我
just gonna do this really quickly boom start equal the event account is the 只是要真的做到这一点，就等于事件帐户是
investor all right the event token is the token address the amount is a 投资者没关系，事件代币是代币地址，金额是
hundred tokens and the rate is also 100 tokens all right 100个令牌，速率也为100个令牌
so copy this you pause the video if you want you to see all that code and 因此，如果您想查看所有代码，请复制此代码，以暂停视频
understand it more I'm gonna run the tests see if it works all right it 更了解它，我将运行测试，看看它是否正常运行
passes perfect so the last thing I want to do before I wrap up this section is 通过完美，所以在结束本节之前我要做的最后一件事是
create a requirement all right so essentially what we want to do is 很好地创建需求，所以本质上我们要做的是
require that this exchange actually has enough tokens so if someone like tries 要求此交换实际上具有足够的令牌，所以如果有人尝试
to purchase it like then if it someone tries to purchase more than the exchange 像这样购买它，如果有人尝试购买比交易所更多的东西
has then it'll fail alright so basically we're gonna say require 然后它会失败的，所以基本上我们要说要求
touken that balance of all right say address this that's greater than or 权衡所有权利，说这等于或大于
equal to token amount all right so essentially that means if somebody 等于令牌数量没事，所以从本质上讲这意味着如果有人
tries to buy more tokens than the exchange has then this will fail so 尝试购买比交易所更多的代币，这将失败
break that down require is just a statement inside of solidity that will 打破要求只是坚固性内的陈述，
say hey if whatever you pass into here if it evaluates to true keep executing 说嘿，如果您传递到此处的任何内容（如果评估结果为true），请继续执行
the function if it evaluates to false stop executing the function and don't do 函数，如果结果为假，则停止执行该函数，不要执行
anything else okay and throw an error okay 没事的话就抛出错误
so we can check the balance of each swap inside this function by saying token 因此我们可以说出令牌来检查此函数内每个交换的余额
balance of right that fetches the balance and then this references the 取得平衡的权利平衡，然后引用
address of the smart contract so this is actually eath swaps address okay and we 智能合约的地址，所以这实际上是可互换的地址，好了，我们
convert it to an address type like this right so basically we just say make sure 将其转换为这样的地址类型，所以基本上我们只说确保
that balance is greater than or equal to the amount of tokens that are getting 该余额大于或等于获得的代币数量
purchased right here all right so make some notes about that 在这里购买正确的，所以做一些笔记
so to say require I swap has enough tokens and then will also make a note 所以说要求我交换有足够的令牌，然后还会做一个记录
here that this transfers tokens to the user all right so I'm gonna save that 在这里，这可以将令牌转让给用户，所以我要保存
run the test again see if it passes and hopefully nothing changed and the tests 再次运行测试，看看是否通过了，希望没有任何改变，然后进行测试
will still work all right there we go so you know we could write a test for this 仍然可以正常运行，所以您知道我们可以为此编写测试
but I'm gonna skip it for now and I'll explain why basically I would have to 但我现在要略过，我将解释为什么基本上我必须
have a million ether or well you know close to a million ether in order to I 有一百万个以太，或者你知道要接近一百万以太
guess I had to have a hundred thousand or ten thousand and something like that 我猜我必须有十万或一万
right a lot of a third order to purchase all the tokens and each swap or more but 正确地以三分之一的顺序购买了所有代币，每次交换或更多，但是
I don't want to really simulate a test scenario where that's possible I'm just 我不想真正模拟一个可能的测试场景
going to trust that this works for now we're gonna test out other requirement 相信现在可以使用，我们将测试其他要求
statements in the next video so you're gonna get 下一段视频中的陈述，您将获得
plenty of practice on that but for now I'm just gonna leave this as is the test 大量的练习，但是现在我要离开这个，就像测试一样
pass and we're gonna stop there for now 通过，我们现在就停在那里
okay so let's continue on we worked on this you swap contract and we created 好的，让我们继续进行此交换合约的工作，我们创建了
the buy tokens function so if you look here you know this is the bide folk 购买代币功能，因此，如果您在这里看，您知道这是比迪烟民
sorry the buy tokens function we created last time now we're going to create a 抱歉，我们上次创建的购买令牌功能现在要创建一个
sell tokens function so we'll do that just like this we'll go ahead and give 出售代币功能，因此我们将像这样进行操作，并继续给予
herself some space here all right and we'll say function say sell tokens just 自己可以在这里留一些空间，我们会说功能只是出售代币
like we would the buy tokens function and I'm gonna even go farther on the 就像我们将购买代币功能一样，我将走得更远
screen okay so what needs to happen inside this function well basically we 屏幕好，所以基本上在这个功能里面需要发生什么
want to do the opposite of what we did here so instead of transferring tokens 想要做与我们这里相反的事情，而不是转移令牌
from the east swap exchange to the investor we want to do it the other way 从东部掉期交易所到投资者，我们想换一种方式
around we want to transfer tokens from the investor to east swap and then we 我们想将代币从投资者转移到东掉期交易，然后我们
also want to give the investor ether okay so we need to write function that 也想给投资者以太币，所以我们需要编写函数
or start some code that performs a sale say perform sale so how do we do that 或启动一些执行销售的代码，例如执行销售，那么我们该怎么做
well first we can give the user ether we could say msg sender say transfer and 好首先我们可以给用户以太，我们可以说味精发送者说转移和
then some sort of ether amount okay so we haven't defined this yet but that's 那么某种以太量就可以了，所以我们还没有定义，但这是
the core code that we're gonna write in order to give the user a theorem okay so 为了给用户一个定理，我们要编写的核心代码
I don't forget msg that sender is the person calling this function Whoopi's 我不会忘记msg，发件人是调用此函数的人Whoopi的
all that in the last section here alright and so transfer is not a 好了，在上一节的所有内容中，所以转移不是
function that you've seen yet inside of solidity for aetherium okay we saw here 您已经看到的功能，但仍在牢固的内部，以太坊好吧，我们在这里看到了
on the token this is you know the transfer function for e rc 20 tokens 在令牌上，这是您知道e rc 20令牌的传递函数
pull that up right here transfer right but here what we're doing is calling 将其拉到此处，传输权，但此处我们正在做的是调用
transfer for ether you know the native cryptocurrency of the etherium 为以太坊转移，您知道以太坊的原生加密货币
blockchain so what we're doing is saying send ether to the person calling this 区块链，所以我们在说将以太币发送给称呼此人的人
function and we want to tell it you know how much we haven't defined this amount 功能，我们想告诉您您知道我们还没有定义多少
yet all right so we're gonna do is pass in an amount here you int amount all 好的，所以我们要做的是在这里传递一定数量
right so basically we're to say you know how many tokens are they selling right 对，所以基本上，我们要说的是，您知道他们正确销售了多少代币
let's say they want to sell 100 tokens will the pass in a hundred here so we 假设他们想卖出100个代币，那么这里的通行证就会变成100个
can calculate this ether amount just like we calculated this token amount 可以计算出以太币的数量，就像我们计算出代币的数量一样
we'll just do the opposite say calculate the amount of ether to redeem and we'll 我们只是做相反的说法，计算要赎回的乙醚量，我们将
say you int ether amount equals amount 说你intether数量等于数量
all right this is the number of tokens that they're selling so we're going to 好吧，这是他们出售的代币数量，因此我们将
take the number of tokens are selling and we're going to divide it by the rate 以卖出的代币数量为准，我们将其除以费率
okay so remember here we multiplied the number of the amount of ether that they 好的，所以请记住，我们将它们乘以
were gonna send by the amount of sorry when we back that up we multiplied the 当我们备份后，我们会乘以抱歉的数量发送
amount of ether they sent when they went to buy tokens by the rate to determine 他们去购买代币时所发送的以太币数量
the token amount so when they sell the tokens we were backwards we take the 代币的数量，所以当他们出售代币时，我们倒退了
amount of tokens that they want to sell and we divide it by the rate to get the 他们想要出售的代币数量，我们将其除以汇率以获得
ether amount that they receive whenever they sell the tokens okay and then we 他们出售代币时获得的以太币数量，然后我们
send them that much right so that sends ether to the investor but now we want to 给他们那么多权利，以便将以太币发送给投资者，但是现在我们要
do is also transfer tokens from the user the investor to the eath swap exchange 还将代币从用户投资者转移到食堂掉期交易所
so that it gets the tokens back you know it's selling the tokens so we had to 这样它就可以收回代币，您知道它正在出售代币，所以我们不得不
send the tokens to the exchange and we also have to you know give ether to 发送代币到交易所，我们还必须知道以太币给
investors so it's a two-way street right so how we do that is we say token and 投资者，所以这是一条双向路，所以我们要做的就是说代币和
then you know here we did transfer your token transfer all right we'll just 那么您知道在这里我们确实转移了您的令牌转移，我们只是
let's do this for now all right and then what we want to do is swap this alright 让我们现在就这样做，然后我们要做的就是交换这个
we could say you know token amount here and then swap them and when I say swap I 我们可以说您知道这里的代币数量，然后交换它们，当我说交换时，
mean instead of sending it to image sender we can send it back to the smart 意味着我们可以将其发送回智能设备，而不是将其发送给图像发送者
contract so we say address this alright we could do that right and that would 合同，所以我们说可以解决这个问题，我们可以做到这一点，那会
essentially transfer the tokens to this which is the smart contract right and 本质上将代币转移到这就是智能合约权利，
then the amount but this isn't gonna work so here's why basically whenever 那么数量，但这是行不通的，所以这就是为什么基本上每当
the investor calls this function it doesn't necessarily we can't let the 投资者称此功能为不一定，我们不能让
smart contract call the transfer function on an ERG 20 token like this on 智能合约像这样在ERG 20代币上调用转移函数
behalf of the investor it's not how I XI 20 tokens work otherwise you could just 代表投资者，这不是我XI 20代币的工作方式，否则您可以
like hide transfer functions inside a smart contract calls without people 就像在没有人的情况下在智能合约调用中隐藏转移功能
instantly knowing about it and you could like you know send your 立即知道它，您可能希望知道发送
money away so in order to avoid that ERC 20 has a special function called 为了避免ERC 20具有称为
transfer from alright and so basically this is what allows other smart 从好的转移，所以基本上这就是允许其他聪明的
contracts to spend your money so we have to use this transfer of thumb function 合同花费您的钱，所以我们必须使用拇指转移功能
inside of here so I transfer from alright and so we say msg sender all 在这里里面，所以我从好的地方转移了，所以我们说msg sender all
right so that's who it's going from that's who it's going to and this is the 正确，这就是要去的人，那是要去的人，这就是
amount so see that here from two amount so this is the special function we use 数量，因此请从两个数量中看出这是我们使用的特殊功能
anytime you want a smart contract to spend your tokens for you okay 任何时候您想要智能合约为您花费代币就可以了
now before we do that you know in the test you'll see that we're gonna have to 现在，在执行此操作之前，您会在测试中知道，我们将不得不
approve tokens first like that's how transfer from works this approved 首先批准令牌，就像这样，这是批准的工作转移方式
function must be called before we can call transfer from will see that and 必须先调用函数，然后我们才能从中调用转移，然后才能看到
play in a minute but we don't have to do that inside of the smart contract 玩一分钟，但我们不必在智能合约内进行
basically we could just do the approval outside of it and then we'll do this 基本上，我们可以在其外部进行批准，然后再执行此操作
transfer from function any type of call cell tokens which we'll see in a minute 我们将在一分钟之内从函数中转移任何类型的调用单元令牌
like basically you have to call approve and then cell tokens and this will work 就像基本上，您必须先致电批准，然后再调用单元令牌，这将起作用
okay so we'll see play right now let's go ahead and test 好吧，现在我们来看比赛吧，让我们继续测试
this out we'll say a chuffa compile make sure there's no syntax errors before we 我们要说一个chuffa编译，确保在我们之前没有语法错误
update the tests all right okay so we got a problem here we need to make this 好的，请更新测试，所以我们在这里遇到问题，我们需要这样做
function public all right so we'll say public that's gonna allow it to be 可以正常使用public函数，所以我们要说public，它将允许它成为
accessed outside of the tongue sorry out the smart contract okay perfect so now 舌头之外访问抱歉，智能合约还不错，所以现在
let's go to the tests you swap tests and we'll create a test 让我们转到交换测试的测试，然后创建一个测试
down here it's go ahead just copy this one say sell tokens alright and we'll 在这里，继续进行下去，只需复制一个说“出售代币”即可，我们将
clear out all this and we'll clear all this 清除所有这些，我们将清除所有这些
we're just making the skeleton in place here all right so for the description 我们只是在这里使骨架就位，所以为了说明
we'll say it allows user to instantly sell tokens instead of purchase to e 我们将说它允许用户立即出售代币而不是购买给e
swap for a fixed price okay so we're sure we reverse that boom 交换固定价格好吧，所以我们确定我们会扭转这种繁荣
it allows you to instantly sell tokens to e swap a perfect price so inside of 它允许您立即出售代币以交换理想价格，因此
here what we want to do is call that function we just created so we'll say 在这里，我们要做的是调用刚刚创建的函数，所以我们将说
results equals a weight eath swap sell tokens all right and let's just sell the 结果等于权重掉期卖掉代币就好了，我们就卖掉
all 100 tokens here that we purchased back to the exchange say tokens 100 and 我们在交易所购买的所有100个代币都说代币100和
we'll say you know from investor right so I'll show you this is gonna blow up 我们会说您知道正确的投资者信息，所以我会告诉您这将会爆炸
I'm sorry truffle tests that's not going to work and I'll illustrate why yeah 抱歉，松露测试无法正常工作，我将说明原因
let's hope it actually doesn't work yeah okay boom so it incurred it reverted all 让我们希望它实际上不起作用，是的，所以繁荣导致它恢复了所有
right so why well it's just like what I was saying a minute ago in order to call 是的，那为什么很好，就像我刚才说的为了打电话一样
transfer from we have to approve the tokens before the smart contract can 在智能合约可以使用之前，我们必须从中转移令牌
spend them for us okay this this function that I'm talking about here 花点钱给我们好吧，这个我在这里谈论的功能
this allow smart contractors spent our tokens 这允许聪明的承包商花费我们的代币
so we have to call this on the token itself before we can call buy tokens or 因此我们必须先调用令牌本身，然后才能调用购买令牌或
start sell tokens on e swap so I'll show you let's say a weight invest our token 开始通过电子掉期出售代币，所以我告诉你，让权重投资我们的代币
so not eath swap but token approve eath swap address all right so this is saying 所以不吃掉交换，但是令牌批准吃掉交换地址，所以这是说
we want each swap to be able to spend the tokens for us and then we specify an 我们希望每次交换都能为我们花费令牌，然后我们指定一个
amount so we'll just say all hundred tokens and then we'll just you know do 数量，所以我们只说所有一百个令牌，然后我们就知道了
the rest of these same arguments so I'll make notes inside of here 其余这些相同的参数，所以我将在这里做笔记
that the investor must approve the purchase and then you know this is the 投资者必须批准购买，然后您知道这是
action where they actually sell the tokens all right so let's just run it 他们实际上可以正确出售代币的行动，所以让我们运行它
and see if it works all right so now it didn't revert so that shows you that we 看看它是否可以正常工作，所以现在它没有还原，向您表明我们
have to approve the tokens before we sell them and this is going to be a 我们必须先批准代币，然后才能出售它们，这将是一个
critical step whenever we developed the client-side application as well okay so 我们在开发客户端应用程序时也很关键，所以
now we want to do is check the investor balance went up or sorry went down so we 现在我们要做的就是检查投资者的余额上升或对不起下降，所以我们
can just copy this example so do this and instead of 100 will just say zero 可以复制这个例子，而不是100只会说零
because they sold them or the tests see if it passes and basically we're going 因为他们出售了它们，或者测试看是否通过了，基本上我们要
to check the opposite in this test of what we looked at for the last test so 在本次测试中检查与上次测试相反的内容
yeah that also worked all right so now we can make sure that the east flat 是的，它也可以正常工作，所以现在我们可以确保东平
balance is corrected for the purchase all right so ease fly balance equals 可以对购买的余额进行更正，这样可以缓解飞行余额等于
awaits token balance of each swap so now it should be back up to you know million 等待每个掉期的代币余额，所以现在应该备份到您知道的百万
one two three four five six and the East five balance should be zero or sorry the 一二三四五六和东五余额应为零或对不起
ether bow should be zero all right so it was back to the way it was when we 以太弓应该是零，所以它回到了我们以前的样子
started this tutorial series or sorry in the first test example yeah awesome 开始了本教程系列，或者很抱歉，在第一个测试示例中，很棒
perfect so that's doing pretty well now let's go 完美，所以现在做得很好，让我们开始吧
ahead and add an event to the sell tokens function just like we did in this 像我们在此操作中一样，将事件添加到Sell Tokens函数中
first example so we'll copy this and instead of tokens purchased or token 第一个示例，因此我们将复制它，而不是购买的令牌或令牌
purchased say tokens sold and tell you what while we're here I'm going to 购买说代币出售，并告诉你我们在这里时我要去
update this name 更新这个名字
let's do tokens plural all right I'm gonna update that say tokens sold this 让我们做令牌复数好吧，我要更新说令牌卖了这个
is probably gonna cause some problems for people so sorry but I just want to 可能会给人们带来一些麻烦，很抱歉，但我只是想
make sure this is it looks good before we continue so same thing it's gonna 在继续之前确保它看起来不错，然后继续
have the same arguments account token amount and rate and then we'll just omit 具有相同的参数帐户令牌数量和费率，然后我们将省略
that at the bottom so let's say you know emit an event like this emit and events 在底部，所以让我们说您知道发出像这样的事件
emit tokens sold then we'll pass an MSG sender address of the token right then 发出售出的代币，然后我们将传递代币的MSG发送者地址
the amount and then the right and then similarly you know we'll go into the 金额，然后是权利，然后类似地，您知道我们将进入
test and copy this same event check right well dig into the logs paste this 测试并复制此同一事件，检查是否正确并深入日志中粘贴此
here let's even say had some comments here say check logs to ensure that the 在这里，我们甚至可以说有一些评论，在这里说检查日志，以确保
event was emitted with the correct data I had this comment here as well and 事件发出了正确的数据，我在这里也有此评论，并且
we'll update these values so you know the account should be the investor 我们将更新这些值，以便您知道该帐户应该是投资者
should be a token address it should be a hundred tokens and the ether amount 应该是一个令牌地址，应该是一百个令牌和以太金额
surely the rate should be 100 all right so let's run the test see if it passes 当然速率应该是100，所以让我们运行测试看看是否通过
all right it worked okay so lastly what I want to do is you know add some 好的，它工作正常，最后我想做的是，您知道添加一些
requirements to this function okay so the first thing we want to do is make 这个功能的要求还可以，所以我们要做的第一件事就是
sure that youth swap has enough ether to redeem the tokens so just like we did 确保青年掉期交易有足够的以太币来兑换代币，就像我们一样
here we want to check the e swap has enough 在这里我们要检查e交换是否足够
ether whenever the sale happens we'll do that 以太币只要有交易发生，我们就会做到
before we perform the sale okay so basically what we do is we can check the 在进行销售之前，基本上可以做的是检查一下
balance like this address this balance all right and we want to make sure it's 这样的余额可以解决这个余额，我们要确保它是
greater than or equal to the ether amount okay and we want to require that 大于或等于以太币数量还可以，我们想要
all right let's just run the test see if it passes okay boom all right so this is 好吧，让我们运行测试，看看它是否通过了繁荣，好吧，这是
a really strange error um and yeah this is this is a kind of a weird thing all 一个非常奇怪的错误，嗯，这是一件奇怪的事
right so this is a real strange quirk you need to go you're truffle - config 对，所以这是一个真正奇怪的怪癖，您需要走松露-配置
file right below here and say EVM version Petersburg all right so I don't 在此处下方文件并说EVM版本Petersburg可以，所以我不
want to get too in-depth on why we need to do this but just try it and hopefully 想要深入了解为什么我们需要这样做，但请尝试一下，并希望
you'll make your test pass it try it again 您将使测试通过，然后再试一次
and there we go awesome so this is really strange quirk but this is a real 我们去的很棒，所以这是很奇怪的怪癖，但这是一个真实的
gotcha just make sure you put this in your treble - config file here in order 只需确保您将其放入高音-此处的配置文件中即可
to continue all right so last thing I want to do is make sure that the I'll 继续没事，所以我要做的最后一件事是确保我会
see here that the user can't sell more tokens than they have okay so I'm gonna 在这里看到用户不能卖出比他们还好的代币，所以我要
write the test first actually and then we're gonna write the code so basically 实际上首先编写测试，然后我们将基本上编写代码
we'll test for failure here failure I'm gonna show you how to test for failure 我们将在这里测试失败，失败，我将向您展示如何测试失败
say investor can't sell more tokens than they have okay 说投资者不能卖出更多的代币
so we'll say oh wait 'if swap sell tokens and we'll try to sell like you 所以我们会说哦，等一下，如果掉期出售代币，我们将尝试像您一样出售
know 500 that's more than the investor currently has and will say if from 知道500比投资者目前拥有的更多，并会说是否来自
combustor I say should be rejected all right perfect so let's run the test it 我说燃烧室应该完美无瑕，所以让我们进行测试
should fail so we expect and then we're gonna write the code to make it pass all 应该失败，所以我们期望，然后我们将编写代码以使其通过所有
right perfect and actually it looks like it passed the first time and that's 完美，实际上看起来像是第一次通过
because probably because the token is throwing an exception not necessarily 因为可能是因为令牌不一定抛出异常
the Swap smart contract okay but what we can do is write an explicit requirement 交换智能合约还可以，但是我们可以做的是写一个明确的要求
in the contract as well that would look like this okay say user can't sell more 在合同中也是如此，说用户不能卖更多
tokens than they have and like I said I think the ERC 20 tokens already taking 令牌的数量超过了他们，就像我说的那样，我认为ERC 20令牌已经在使用
care of this for us but we're gonna do it for tutorial 为我们照顾这个，但我们将在教程中进行
purposes just to show you explicitly how you do it inside the smart contract say 目的只是为了向您明确显示您如何在智能合约中说
we require token balance of MSG at sender is greater than or equal to 我们要求发送方的味精令牌余额大于或等于
amount right I think it's because it's trying to Trent I think whenever it 数量正确，我认为这是因为它试图在Trent上行驶，我认为
calls the transfer from function its trying to you know move tokens that you 调用从函数进行的转移，试图知道您是否移动了令牌
don't have so it's gonna throw an error anyway but we're just going to add this 没有，所以无论如何都会抛出一个错误，但是我们将添加它
here so you can see how you check for yourself and there we go still passes 在这里，您可以看到如何检查自己，然后我们仍然经过
awesome so that's it guys that is the completed smart contract code 太棒了，这就是完整的智能合约代码
congratulations you've come a really long way and a series so far so there's 恭喜，您走了很长的路要走，到目前为止已经取得了一系列进展，
one final step before I move on to the next section this is really important 在进入下一部分之前的最后一步，这真的很重要
don't miss this we want to put the smart contracts the completed smart contracts 不要错过这个，我们想将智能合约作为已完成的智能合约
on the blockchain so we'll a truffle migrate - - reset and that's going to 在区块链上，所以我们将松露迁移--重置，这将
put them on the blockchain and also put the final compiled versions inside of 将它们放在区块链上，还将最终的编译版本放在
our truffle project like this you can go to source or actually start build where 像我们这样的松露项目，您可以转到源代码或实际开始构建
is it source contracts sorry it source ABI is 是源合同吗，对不起，源ABI是
my fault I swap alright so here's the completed 我的错，我换了，所以这是完成的
smart contract and it even gives you the C Network shows you the address of it on 智能合约，它甚至可以为您提供C网络，向您显示它的地址
the network all that kind of stuff awesome alright everybody so 网络上所有这些东西真棒大家
congratulations that's it and now we're going to do is start building out the 恭喜，就这样，现在我们要做的是开始构建
client-side website or user interface which you see here so really quickly if 您在此处看到的客户端网站或用户界面非常快，如果
you liked this tutorial series go ahead and subscribe to the channel and put the 您喜欢本教程系列，请继续订阅该频道，然后将
like button down below that really helps these videos get found 例如下方的按钮，确实有助于找到这些视频
with a youtube algorithm and also if you want to take that next step towards 使用youtube算法，如果您想朝着
mastering blockchain then head on over to dap university comm for it slash 掌握区块链，然后前往Dap University comm进行斜线切割
bootcamp all right so let's continue on with this right this is the finished 训练营好吧，让我们继续吧，这是完成的
product that we're working toward and right now you know we have just a really 我们正在努力的产品，现在您知道我们只有一个
bare-bones website this is the starter kit that we you know began the product 裸机网站，这是您知道开始该产品的入门工具包
with we haven't really modified the code for this at all and so that's what we're 我们根本没有真正修改此代码，这就是我们要做的
gonna do in this tutorial at least in this part of the video so we're going to 至少要在视频的这一部分中进行本教程的介绍，所以我们将
connect this to the blockchain alright we're gonna load our account and put it 将此连接到区块链好吧，我们将加载我们的帐户并将其放入
here and wire up this identic on and we're gonna get started with all of that 在这里并连接这个标识，我们将开始所有这些
right now so a few quick housekeeping tips you 现在，让您快速掌握一些整理技巧
know if you're just picking up at this point the tutorial make sure you have 知道此时您是否正在接机，本教程确保您已
your a node packages installed you can just do that with NPM install right that 您的节点软件包已安装，您只需使用NPM安装即可
makes sure that you have all the dependencies on your computer to run the 确保您拥有计算机上的所有依赖项才能运行
project make sure that you have your webserver running you know I've got mine 项目确保您的Web服务器正在运行，您知道我已经拥有我的
here in a separate terminal tab but you can start your webserver with NPM run 在一个单独的终端选项卡中，但是您可以使用NPM run启动您的网络服务器
start all right next make sure that ganache is running this is your 接下来开始一切正常，确保ganache正在运行，这是您的
development blockchain right make sure it looks like this and you see your 开发区块链正确，确保它看起来像这样，您会看到
accounts with ether and then finally make sure that your completed smart 用以太币帐户，然后最后确保您已完成
contracts are migrated to ganache as in you've actually put them on the 合同已迁移到ganache，就像您实际上将它们放在
blockchain and you can do that like this shuffle my gray - - reset okay okay so 区块链，您可以像这样洗刷我的灰色--重置好的好的，所以
again yeah I've done all those commands so you don't have to that's why I didn't 再次，是的，我已经完成了所有这些命令，所以您不必这样做，这就是为什么我没有
click enter but you should if you haven't done those yet all right so 单击Enter，但是如果还没有做的话应该这样做
let's go ahead and open up the project again and kind of take a quick tour of 让我们继续并再次打开该项目，然后快速浏览一下
the client side application before we start modifying it 开始修改它之前的客户端应用程序
we go to source components all right go to app DJ s and here's the main 我们转到源组件，然后转到应用程序DJ，这是主要的
component that we'll use for this tutorial we'll start here you can see 我们将在本教程中使用的组件从此处开始，您可以看到
the code for this page right here go here all right deputy diversity starter 此页面的代码就在这里，在这里，好吧，副主席，多样性多样性初学者
kit Dappy diversity starter kit so we're gonna basically just start editing this 工具包Dappy Diversity入门工具包，所以我们基本上将开始编辑它
I'm gonna clear out all the code inside of here let's just do this and make sure 我要清除这里的所有代码，让我们这样做并确保
we can actually update it make changes forgot that and we'll just say you know 我们实际上可以对其进行更新，使更改忘记了，而我们只是说您知道
hello world yeah awesome so are your first page and there we go 你好，世界，太棒了，您的首页也去了，我们去了
boom and we're going to eat the logo out and we'll remove it from the top as well 繁荣，我们将吃掉徽标，我们也将从顶部将其删除
and there we go okay so we've got a fresh palette to work with and now we're 然后我们就可以了，所以我们可以使用一个新的调色板，现在
going to do is go ahead and connect the application to the blockchain well 要做的是继续将应用程序很好地连接到区块链
actually before we do that let me make a quick mention of react.js and kind of 实际上，在我们这样做之前，让我先快速介绍一下react.js和
how it works so you don't have to be experienced with react in order to 它是如何工作的，因此您不必具有反应的经验即可
follow along with this tutorial I think you can pick up a lot about react just 跟随本教程一起学习，我想您可以从中获得很多关于反应的知识
by watching me code and you know building something and react yourself 看着我的代码，你就会知道建立一些东西并做出自己的反应
so basically react tjs is a JavaScript library for building user interfaces 所以基本上react tjs是一个用于构建用户界面的JavaScript库
alright so what it does is it organizes your code into these things called 好吧，它的作用是将您的代码组织成称为
components and that's what you see here you see class app extends components all 组件，这就是您在此处看到的类应用程序扩展了所有组件的结果
right we're pulling in component right here from the reactor library which we 正确的是我们从反应堆库中提取组件
installed inside of our package JSON file okay so basically these JavaScript 可以安装在我们的包JSON文件中，所以基本上这些JavaScript
files you know nsj right here they actually 您在这里实际上知道nsj的文件
mix HTML code and JavaScript code okay so you can see like this is JavaScript 混合HTML代码和JavaScript代码，这样您就可以看到像JavaScript
right here class extends component render is a function in JavaScript it 就在这里，类扩展了组件渲染是JavaScript中的一个函数
has a return and inside the return this is all HTML code that we see here 有一个返回，在返回里面，这是我们在这里看到的所有HTML代码
a webpage right right here all right so inside the HTML code you can also 正确的网页，因此在HTML代码中，您还可以
execute JavaScript so if I undo like what I did a minute ago you see this 执行JavaScript，所以如果我像一分钟前那样撤消操作，您会看到此信息
source logo right if I go back even further yeah 源徽标正确，如果我再回去的话，是的
source logo basically these curly braces anything inside the curly braces is 源徽标基本上这些花括号花括号内的任何东西都是
JavaScript essentially so this logo right here is a variable that was 本质上是JavaScript，因此此处的徽标是一个
imported right here from the image and basically this is just the path to the 从图片中直接导入，基本上这只是通向
image okay so I'm gonna redo all that and well sorry yeah you just kill that 图像还可以，所以我要重做所有这些，很抱歉，是的，您只是杀死了那个
and manually redo it go back to page here all right so yeah anyways I'll take 并手动重做，回到页面上可以，所以无论如何我都会
another quick tour of react so it's component base yeah this is what a 另一个快速的反应之旅，所以它是组成部分，是的，这是一个
component looks like you know you can see this class hello message that looks 组件看起来像您知道的那样，您可以看到此类的类hello消息
a lot like our app component let's see here so the next thing is react State 很像我们的应用程序组件，让我们在这里看到，所以接下来是反应状态
all right this is gonna be a critical concept to understand as we build this 好吧，这将是我们构建此模型时要理解的关键概念
tutorial essentially react State is sort of like a database kind of on the front 教程本质上是反应状态有点像数据库一样
end it's a place where all the the data for the application goes so for example 最后是一个存放应用程序所有数据的地方，例如
you know if you were gonna build a to-do list and react only right you can see it 你知道你是否要建立一个待办事项清单并且只做出反应就可以看到它
to-do list well where do you store all the to-do items on the to-do list right 待办事项列表很好，您将待办事项列表上的所有待办事项存储在哪里
if I say item 1 and click add item 1 and say item 2 like where do these go well 如果我说第1项，然后单击添加项目1并说第2项，例如这些操作进展顺利
they get stored and reacts State object which kind of acts like a little tiny 他们被存储起来并反应State对象，这种行为有点微小
database right it's not persistent you know if you refresh the page everything 数据库权利不是持久性的，您知道是否刷新页面所有内容
goes away but it's a little temporary kind of database ish object inside the 消失了，但这只是其中的一种临时的数据库类对象
react component all right so you can see it right here this is the react state 好的react组件，所以您可以在这里看到它，这是react状态
object right here say this state equals this object and that's where you'd store 对象在这里说这个状态等于这个对象，这就是您要存储的位置
like all the items in the to-do list alright so for our tutorial we're gonna 就像待办事项列表中的所有项目一样，因此在本教程中，我们将
make pretty heavy use of the react state object to store all the data that comes 大量使用react状态对象来存储所有出现的数据
back from the blockchain like the person's balance how many total how many 像人的余额一样从区块链中退回
how much ether they have and your their account address and all that kind of 他们有多少以太币，您的账户地址以及所有此类
stuff ok so let's see here if there's anything 好的，所以让我们看看这里是否有任何东西
else to make note of I think that's a pretty good overview to get started 别忘了我认为这是一个很好的入门指南
we'll see all this stuff in play and I'll reference the reactive 我们将在游戏中看到所有这些东西，我将参考反应式
documentation and get a little bit later when we wire up our component so let's 文档，稍后再连接组件时，请稍等
go ahead and do that let's let's connect our website to the blockchain alright so 继续做，让我们将我们的网站连接到区块链
in order to like turn this application into a blockchain application two things 为了喜欢将此应用程序变成区块链应用程序两件事
need to happen all right so the first thing is connect app to blockchain and 需要一切正常，所以第一件事就是将应用程序连接到区块链，
then second is connect browser to blockchain right so even if you connect 其次是将浏览器连接到区块链，所以即使您连接
your app to the blockchain if your browser can't use the app with the 如果您的浏览器无法将应用程序与
blockchain it's no good alright so we're going to do each of those things right 区块链不好，所以我们要正确地做每一件事
now first let's actually do the browser to 现在首先让我们实际使用浏览器
the blockchain that's the easier part and it has to be done first before we 区块链是更容易的部分，必须首先完成
can really successfully make use of this part so we're gonna stack words right so 可以真正成功地利用这一部分，所以我们要正确地堆叠单词
in order to connect your browser to blockchain we're gonna use meta mask 为了将您的浏览器连接到区块链，我们将使用元掩码
alright you installed this at the very very beginning of the tutorial okay so 好了，您在本教程的最开始就安装了此程序，所以
make sure you've got metamath setup properly go back and revisit that 确保您已正确设置Metamath返回并重新访问
section if you haven't already all right so basically if you open this little fox 部分，如果您还没有很好，那么基本上，如果您打开这只小狐狸
icon you know you'll probably see a count 1 图标，您知道您可能会看到一个计数1
right here this is your first time using meta mask and you know you probably 在这里，这是您第一次使用meta mask，您可能知道
connected the main net right here so the first thing you want to do 在这里连接主网，所以您要做的第一件事
well actually it's sorry let me explain Matt a mask essentially your web browser 好吧，实际上我很抱歉让我解释一下Matt基本上是您的网络浏览器的面具
by default doesn't talk to the blockchain you need a special browser 默认情况下不与区块链对话，您需要特殊的浏览器
extension in order to do that and that's what meta mask does so this is an 扩展才能做到这一点，这就是元掩码的作用，所以这是一个
ethereal wallet alright wallets are how you connect to 空灵钱包好钱包是您连接的方式
the blockchain and what you want to do first is connect to the correct 区块链，您首先要做的是连接到正确的
blockchain okay so if you click this button up here yours probably says main 区块链好吧，所以如果您在此处单击此按钮，您可能会说主要
if the ARIMA network you want to do custom RPC all right and we can call 如果您想对ARIMA网络进行自定义RPC，我们可以致电
this ganache and say HTTP colon 4 slash forward slash local hosts port 75 45 这个ganache并说HTTP冒号4斜杠正斜杠本地主机端口75 45
alright so I have already done this so it won't let me save it anyways just 好吧，所以我已经做到了，所以无论如何我都不会保存它
click Save so then go and select the instance you just created I'll go ahead 单击“保存”，然后选择您刚刚创建的实例，我将继续
and select annachi err alright so once you've done that you'll have correctly 并选择annachi err好，所以一旦完成，您将正确
connected to your development blockchain that's this right here okay so the next 连接到您的开发区块链就可以了，所以下一个
thing I want to do is import this account right here the very first 我想做的就是首先在这里导入此帐户
account that's important into meta mask so you'll click this little key icon 帐户对于元掩码非常重要，因此您将单击此小钥匙图标
right here so show your private key alright you can copy it click OK so I 在这里，请显示您的私钥，可以复制它，单击“确定”，这样我
mean make sure you don't actually use this to store any real money because 意思是要确保您没有真正使用它来存储任何真实货币，因为
everyone who's watching this video will have seen it and then go over here go to 观看此视频的每个人都会看过该视频，然后转到此处转到
med mask click you'll see you're gonna counts import account and then make sure med mask单击，您会看到您要计算进口帐户，然后确保
this says private key right here on select type and then paste in your 这说私钥就在这里选择类型，然后粘贴到您的
private key and click import so it's gonna tell me I've already done it 私钥并单击导入，这样它会告诉我我已经完成了
because I have but you should basically you know see success and you should see 因为我有，但您基本上应该知道成功，并且应该看到
your account connected right here alright so once that successful you 您的帐户在这里正确连接，一旦成功，您
should see an ether balance right here and you know your ganache network 应该会在这里看到以太平衡，并且您知道您的ganache网络
selected ok so that's step one right connecting your browser to a blockchain 选择确定，所以这是将浏览器连接到区块链的第一步
so meta mess does that and then the second thing is connecting your app to 因此meta meta做到了，然后第二件事是将您的应用程序连接到
the blockchain so we're going to use a special library for that alright call 区块链，所以我们将使用一个特殊的库进行正常调用
web 3j s and you've already seen web 3 a little bit in this tutorial whenever we web 3j s，无论何时我们在本教程中都已经看过web 3
built out the tests right if you go back to let's see your source test or test 如果您回头看看源测试或测试，就可以正确构建测试
test test I swap test you'll see let's see here web 3 utils you know two-way 测试测试我将交换测试，您将看到让我们在这里看到您了解双向的Web 3实用程序
you'll also see like web 3 let's just search for it web 3 eath get balance 您还会看到类似web 3的信息，让我们搜索它吧，web 3 eath得到平衡
stuff like that so we've already used web 3 a little bit but we're going to 像这样的东西，所以我们已经稍微使用了Web 3，但是我们要
use it on the client side in order to connect to the blockchain that's what it 在客户端使用它以连接到区块链
does and basically how web 3 works is it works with the concept of an aetherium web 3的工作原理以及它的基本工作原理是否与aetherium概念一起工作
provider so basically you know meta Mask connects to an aetherium node to talk to 提供者，所以基本上您知道meta Mask连接到以太节点并与之通信
the blockchain that's what it does with ganache and then meta mass exposes that 用ganache做的区块链，然后meta mass将其公开
as a provider to the web 3 JS library so basically it's just that's that's the 作为Web 3 JS库的提供者，所以基本上就是这样
point of connection that you can start using in your application 您可以在应用程序中开始使用的连接点
so it's going to get started doing that so what I'm gonna do is go to my main 所以它将开始做，所以我要做的就是去我的主
component here go to the App J's file alright go here and the first thing we 这里的组件转到App J的文件，然后转到第一件事
want to do is import web 3 into this file ok so this is how we do it instead 要做的是将Web 3导入到该文件中，所以这就是我们的方法
of react we use this import here and we do like this import capital web 3 from 的反应，我们在这里使用这种进口，我们确实喜欢从
lower case web 3 with you know single quotation marks around it and I'm gonna 小写的web 3，您知道它周围的单引号，我要
go ahead and kill these semicolons just for consistency we don't need them all 继续并杀死这些分号只是为了保持一致性，我们并不需要全部
right and so basically we can load up web 3 inside of our component like this 对，所以基本上我们可以像这样在组件内部加载Web 3
ok new function so here's you know this render function will create a new 好的新功能，所以您知道此渲染功能将创建一个新的
function here called load web 3 say load web 3 alright and inside of here is 此处的功能称为“加载腹板3”，说“加载腹板3”
where we're gonna pull the etherium provider from meta mask and expose it to 我们要从元掩码中拉出etherium提供程序并将其暴露给
our application alright so essentially I don't want to 我们的应用程序还可以，所以本质上我不想
reinvent the wheel here I'm basically just gonna use meta masks own 在这里重塑方向我基本上只是使用自己的meta面具
instructions on how to do this so meta mask just tells us you know straight-up 有关如何执行此操作的说明，因此meta mask只会告诉我们您知道正确的方法
how to do this we don't have to reinvent the wheel here you know here is their 如何做到这一点，我们不必在这里重新发明轮子，您知道这里是他们的
suggested code on how you connect to meta mask with your web 3 provider ok 关于如何使用Web 3提供程序连接到Meta Mask的建议代码，确定
I'm sorry with web 3 library so I'm just going to take this and modify and put it 对于Web 3库，我感到很抱歉，所以我将采用它并进行修改并将其放入
straight to the application so don't necessarily worry if you understand 直接进入应用程序，因此如果您理解就不必担心
everything that's going on here this is just kind of like what they tell us to 这里发生的一切，就像他们告诉我们的
do okay so essentially what it does is it looks 做得好，所以本质上是它看起来
for two different things one is window aetherium and window dot web 3 and this 对于两个不同的东西，一个是窗口以太网和窗口点网3
is basically for modern web browsers they'll have this and legacy web 基本上是针对现代网络浏览器，他们将拥有该网站和旧版网络
browsers will have this and if you don't have met ematic installed will show the 浏览器将具有此功能，如果尚未安装ematic，则会显示
user and alert you know not aetherium browser connected please use matt mask 用户并提醒您知道未连接以太网浏览器，请使用无光面罩
alright so the next thing we want to do is make this asynchronous or start make 好吧，所以我们接下来要做的是使这个异步或启动make
this yeah support the oh wait keyword right so we 是的，这支持oh wait关键字，所以我们
have to do a sync so now we want to call this so in order to connect to this i'm 必须做一个同步，所以现在我们要调用这个以便连接到这个我
going to create new method here called component will 要在这里创建新方法称为组件将
mount alright and then inside if you're able to say it wait this load web three 安装好，然后在里面，如果您能说它等待此加载网络三
I'm sorry I can't code today eyes and then if we're using the awake keyword 对不起，我今天不能编码眼睛，然后如果使用awake关键字
here we also have to make this asynchronous async and then I'm gonna 在这里，我们还必须使这个异步异步，然后我要
say console dot log say window dot web three alright so we'll do that go back 说控制台点日志说窗口点网三个好，所以我们将其返回
to our project here and then open this go to console and there we go there's 到这里我们的项目，然后打开它进入控制台，然后我们去那里
our web three instance awesome so web three is we're going to use 我们的网络三实例很棒，所以我们要使用网络三
inside our application to connect the blockchain if you go back to our tests 如果您返回到我们的测试，则可以在我们的应用程序内部连接区块链
you'll see we can do stuff like get the users current balance right web three 您会看到我们可以做一些事情，例如让用户保持当前的网络平衡3
eath get balance we can do all kinds of stuff and so make it quick mention this Eath可以保持平衡，我们可以做各种事情，因此请快速提及
component will mount this is a special lifecycle method and react that runs 组件将挂载这是一种特殊的生命周期方法，并且会运行
whenever this component is going to get mounted to the react virtual Dom so it 每当将此组件安装到react虚拟Dom时，
gets called before render so essentially you know before we lay out what it was 在渲染之前被调用，因此从本质上讲您知道我们进行布局之前
saying is before we lay out all this HTML content on the page do this alright 这是在我们在页面上布置所有这些HTML内容之前执行的操作
we want to wait for this to finish before all this happens let's continue 我们要等到一切完成后再继续
on here I'm going to remove this console logging statement so now what I want to 在这里，我将删除此控制台日志记录语句，现在我要
do is create another function that will actually import all the data into the 做的是创建另一个函数，该函数实际上会将所有数据导入到
application that we need that's currently stored on the blockchain 我们需要的应用程序当前存储在区块链中
alright so we'll call this wait this load blockchain data alright and then 好吧，所以我们将其称为等待负载链数据，然后
we'll create this function here and be asynchronous async load blockchain data 我们将在此处创建此函数，并进行异步异步加载区块链数据
alright make this a function so the first thing I want to do is we're 好吧，使它成为一个函数，所以我要做的第一件事就是
windowed at web 3 to a variable for shorthand so do we have to keep keep 在网页3上开了一个速记变量，所以我们必须保持
retyping window which we're going to call web 3 a lot in this function 重新键入窗口，我们将在此功能中多次调用web 3
throughout the rest of this tutorial but the first thing I want to do is actually 在本教程的其余部分中，但我要做的第一件事实际上是
fetch the account that we're connected with inside met a mask alright so we 提取我们内部连接的帐户遇到一个掩码，所以我们
want to take this account and pull it out so we can use it in our application 想要使用此帐户并将其取出，以便我们可以在应用程序中使用它
so if you look at our finished products right you know it shows our account here 因此，如果您看我们的成品，就知道它在这里显示了我们的帐户
it reads the balance the ether balance and also 它读取余额，以太余额，以及
touken balance so we need this account to put all this information on the page 头寸余额，所以我们需要这个帐户将所有这些信息放在页面上
it's sort of the first step so if you look at the web 3 documentation here 这只是第一步，因此如果您在此处查看Web 3文档
this is how we fetch the accounts from metamath cards just web 3 eath get 这就是我们如何从metamath卡中获取帐户，只是web 3 eath得到
accounts all right so it's pretty simple appreciate forward and we can do that 没关系，所以很简单地感谢您，我们可以做到
just like this I was like Const accounts equals a weight web 3 eath get accounts 就像这样，我就像Const帐户等于权重网站3的账户
all right and then we'll say console.log accounts all right so let's go wrap 好的，然后我们将说console.log帐户，所以让我们开始吧
okay so accounts is not fine it's like I just made a typo here there we go so 好的，所以帐户不正确，就像我在这里打错了一样
here's the account that we're connected with the meta mask all right so to a EC 这是我们已经与meta mask连接的帐户，所以可以连接到EC
right to a EC so that looks correct and you'll see this is inside of an array so 右转到EC，这样看起来正确，您会看到它在数组内部，因此
really this is like could be multiple accounts but there's only one inside of 确实，这就像是多个帐户，但是里面只有一个
here and the first one is the account that we want to connect to so we can 在这里，第一个是我们要连接的帐户，因此我们可以
just fetch that out of the array you know you can just say like here's an 只需从数组中取出它，您就可以说这就像一个
array with you know different write foo bar Baz and this is an array something 与您知道的数组不同，请写foo bar Baz，这是一个数组
with the first item out of this array basically oops sorry array equals 4 with 该数组中的第一项基本上会抱歉，数组等于4
the first item at this array we just say array 0 and there you go so we'll do the 在这个数组的第一项，我们只说数组0，然后你走了，所以我们将
same thing with the accounts console we'll just do like this 与帐户控制台一样，我们将像这样
counts 0 and then there you go so you know arrays with zero based index 计数为0，然后就开始计算，所以您知道索引从零开始的数组
so the first item is 0 the second item is 1 third item is 2 etcetera etc so 所以第一项是0第二项是1第三项是2等
next we want to do is actually store this in the react state alright so if 接下来我们要做的是将其实际存储在react状态下
you go back to our reactant ation here I talked about this briefly earlier you 您在这里回到我们的反应物上
know the state is how we keep track of all the data and in this case we're 知道状态是我们如何跟踪所有数据，在这种情况下，我们
going to store the blockchain data inside the state so let's follow reacts 将要在状态内存储区块链数据，所以让我们跟随反应
own instructions on how to set up the state so I'm just going to copy this 关于如何设置状态的说明，所以我将复制此内容
this is what it tells us to do all right just below star just above the render 这就是它告诉我们在渲染下方正上方的星星下方执行所有操作的原因
function I'm gonna paste this in alright so 功能，我要把它粘贴好
got the semicolons here for consistency's sake kill this because we 为了一致性的缘故，在这里得到分号将其杀死，因为我们
don't need that all right so this is basically what we need to do we need to 不需要所有的权利，所以这基本上是我们需要做的，我们需要
take all right we just call this super because what it does it takes the 没关系，我们称之为超类，因为它需要做什么
constructor function well sorry let me back up the constructor function is just 构造函数很好，对不起，让我备份构造函数只是
like the constructor function we saw in our smart contracts if you go back to 就像我们在智能合约中看到的构造函数一样
components or sorry contracts source contracts you know you swap we have a 组件或对不起的合同，您知道您互换了源合同，我们有一个
constructor function inside of there as well so this is the you know function 里面的构造函数，所以这就是你所知道的函数
that gets run whenever the smart contracts created similarly this is the 只要类似创建的智能合约就可以运行
function that gets run whenever the component is created alright and you 只要创建组件就可以运行该函数
know we're inheriting from a different component here or extending so what this 知道我们是从这里的其他组件继承或扩展的
does is it calls the constructor function on the component that we are 确实是它在我们正在使用的组件上调用了构造函数
extending and then we execute our own code inside of here okay so what this 扩展，然后我们在这里执行我们自己的代码，好吧，这是什么
does is it sets up the default state all right so in this case we want to say the 这样做是否可以设置默认状态，所以在这种情况下，我们想说
default account is gonna be equal to an empty string okay so then what we want 默认帐户将等于一个空字符串好吧，那么我们想要什么
to do is actually set this value alright and we do that with the special 要做的就是设置好这个值，我们使用特殊的
functions I react like this let's say this set state and then we pass it an 我像这样反应的功能让我们说这个设置状态，然后我们将其传递给
object okay and we say account and we'll say it counts zero alright and then what 对象好吧，我们说帐户，我们将说它计数为零，然后是什么
we can do is log this back out we can fetch it back out from state sorry and 我们可以做的是将其注销，我们可以从状态中获取它，抱歉，
say let's see this state that count and it should be the same thing alright boom 说，让我们看一下这种状态，这应该是一回事
there you go it's the same awesome so we can do the important thing to like note 在那里，您的体验也很棒，所以我们可以做重要的事情来喜欢笔记
is that we set this state here so that we can access the data and other 是我们在这里设置此状态，以便我们可以访问数据和其他
places in the application so for example I can call console.log you know this 放置在应用程序中，例如，我可以调用console.log您知道
state account died here in the render function right which I couldn't do 状态帐户在渲染功能中死亡，我无法这样做
earlier without putting in the state somebody that hit refresh still works 更早地进入状态不会有人刷新
right perfect alright so now what I want to do is fetch the balance okay so we've 对完美好吧，所以现在我想做的就是取得平衡，所以我们
got the account from meta mask and eventually we want to show this ether 从meta mask获得了帐户，最终我们要显示此以太币
balance here and we can do that next inside of our account or sorry inside of 您可以在这里余额，然后我们可以在帐户内进行下一步操作，也可以对不起
our application so we've seen that before actually so if you go back to the 我们的应用程序，所以我们之前已经看到过，所以如果您返回到
tests you swap tests so you get balance eath get balance all right look here 测试您交换测试，以便您获得平衡饮食获得平衡一切正常
recheck the eath swap balance before we did web 3 eath get balance so let's just 在我们进行网络3预算获取平衡之前，请重新检查预算交换余额，所以让我们
copy this from the test since you've seen it before and do it inside of their 因为您之前已经看过，所以可以从测试中复制并在他们的内部进行
front-end application alright so instead of each swap balance 前端应用程序可以，所以不用每个交换余额
we'll just call this const balance I will say eath balance and this 我们将其称为常量平衡，我会说食堂平衡，
is going to be the balance of this account right not east swap it's gonna 将会是这个帐户的余额，而不是东部掉期
be the user who's connected to the application will say this state account 连接到应用程序的用户将说出该状态帐户
and we'll store it to the state just like we did with the other one say this 然后将其存储到状态，就像我们与另一个人说的一样
set state I must say eath balance equals each balance now I'm gonna show you a 设置状态，我必须说，食堂平衡现在等于每个平衡，我要告诉你
pretty cool thing in JavaScript you know in this version of JavaScript and es6 if 您在此版本的JavaScript和es6中知道的JavaScript中非常酷的东西
you have a key and a value of a variable type or sorry let me explain that better 您有一个键和一个变量类型的值，或者抱歉，让我更好地解释一下
if you have a key that has a variable value and they had the exact same name 如果您有一个具有可变值的键，并且它们具有完全相同的名称
you could just do this you can you don't even need the key or the colon you could 您可以做到这一点，甚至可以不需要键或冒号
do that okay so that's the same as doing this because they have the same name and 这样做没问题，所以与这样做相同，因为它们具有相同的名称，
you couldn't do that here because it's not the same okay so now let's at the 您无法在此处执行此操作，因为它不一样，所以现在让我们来
default state and let's say the default balance eath balance is zero right and 默认状态，假设默认余额均衡为零，
then let's do console.log this that state 然后让我们做console.log这个状态
eath balance okay there you go boom so you see that looks right so 食堂平衡好吧，你走了，所以你看看起来很对，所以
ninety seven point eight seven three ether alright so you know you don't see 九十七点八七三以太好吧，所以你知道你没有看到
a decimal place here and that's okay remember that i explained in the 小数点后一位，没关系，记得我在
previous videos that ether is expressed in way when you move it around so that's 以前的视频中，以太在移动时会以某种方式表达，所以
the smallest nomination so basically you know it's like a like a penny for a 最小的提名，所以基本上您知道这就像一分钱
theory i'm a really tiny penny and it's got you know eighteen decimal places 从理论上讲，我是一个很小的一分钱，但您知道十八位小数
after zero you don't use decimals so that's why you see this big number 零后，您不使用小数，这就是为什么您看到这个大数字
good all right so now what i want to do is show the count that we just loaded on 好吧，所以现在我想做的是显示我们刚刚加载的数量
the page right we want to put it up here just like this finished product okay and 就像这个成品好吧，我们想将其放在此处的页面上，
we also want to add this cool icon that's generated automatically with our 我们还想添加一个很酷的图标，它是由我们自动生成的
etherium address so the first thing i want to do is actually move the navbar 以太坊地址，所以我要做的第一件事实际上是移动导航栏
to its own component all right so you're gonna see a really nice benefit of using 正确地使用它自己的组件，因此您将看到使用的真正好处
react components is that we can create more components just like this one that 反应组件是我们可以像这样创建更多组件
are reusable in other parts of our application alright so i'll create a new 可以在应用程序的其他部分重复使用，所以我将创建一个新的
file like this sorry new file and we'll say navbar capital in navbar dot j s 像这样对不起的新文件的文件，我们将在navbar dot js中说出navbar capital
okay and so i might do is just copy all this and then do this take out these two 好吧，所以我可能要做的就是复制所有这些内容，然后将其取出
alright and then take out pretty much all this alright so we got our render 好，然后把所有这些都拿出来，好了，我们得到了渲染
function here and then we'll just take the navbar part all right and then do 在这里运行，然后我们将导航栏部分没问题，然后执行
this and then we'll rename this this app to navbar oops start navbar alright 这个，然后我们将这个应用程序重命名为navbar oops start navbar
that's pretty much all we need to do for this component for now now let's go 现在，我们几乎需要为此组件做的所有事情
ahead and import it into our project here sorry our main component so you can 并将其导入到我们的项目中对不起我们的主要组件，因此您可以
do this you can say import a navbar from dot four slash capital in navbar 为此，您可以说从导航栏中的点四斜杠大写导入导航栏
OOP sorry net bar save that and then let's go let's see here let's just go OOP对不起，网吧保存了一下，然后走吧，让我们看看这里，走吧
back to the website and make sure that everything it looks right alright let's 返回网站并确保一切看起来正确，让我们
go here I'm and cook refresh and nothing changed that's okay we didn't actually 去这里，我在煮饭，没有任何变化，没关系，我们实际上并没有
render out the navbar on this page I just want to make sure that it imported 渲染出此页面上的导航栏，我只想确保它已导入
properly without any errors so it did and say well let's go ahead and change 正确无误，做到了，说得好，让我们继续进行更改
the name here so that we can see our new navbar the page will this call this beef 这里的名称，以便我们可以看到我们的新导航栏，页面将其称为牛肉
swap alright save that refresh the page so we don't see eath swap yet that's ok 交换好吧，保存刷新页面，所以我们看不到Eath交换，但是还可以
because we haven't moved the nav bar down here so now we want to do is take 因为我们还没有将导航栏移到这里，所以现在我们要做的是
out all this code right here and just say let's make this symbol a greater 在这里列出所有这些代码，只是说让我们将此符号做得更大
than symbol or less than symbol sorry navbar capital in nav bar and then 大于符号或小于符号对不起，导航栏上的导航栏资本，然后
forward slash there we go awesome now we should see east wob boom there we go 向前斜线，我们去的很棒，现在我们应该看到东沃伯繁荣
east swap so there's our new nav bar on the page so what we've done here is 东交换，所以页面上有我们的新导航栏，所以我们在这里所做的是
created a new react component right like like this here's a new nav bar and its 像这样创建了一个新的react组件这是一个新的导航栏及其
own components and we've imported it and then we've rendered it out on the page 自己的组件，我们已经将其导入，然后将其呈现在页面上
and reduced you know the amount of code that we see here down to this one line 并减少了您知道我们在此处看到的代码量
ok so now we want to do is show the account here on the page so in order to 好的，所以现在我们要做的是在页面上的此处显示帐户，以便
do that we need to pass the account down to here so basically what we've done is 这样做，我们需要将帐户传递到这里，所以基本上我们要做的是
we've loaded the account we've set it in the react state that we defined here but 我们已经加载了帐户，并将其设置为此处定义的react状态，但是
the problem is this component right here doesn't necessarily know about the state 问题是这里的组件不一定了解状态
for this component like the state just belongs to this component so we can pass 对于该组件，例如状态仅属于该组件，因此我们可以通过
it down like this we can say account equals then 这样下来我们可以说账户等于
do some curly braces this that state account 做一些大括号这个状态帐户
all right and then inside of the navbar here we can render the navbar the page 好的，然后在导航栏内部，我们可以在页面上渲染导航栏
or sorry we can render the account on the page like this we can just say let's 或抱歉，我们可以在此页面上呈现该帐户，我们可以说让我们
just do a paragraph here for now and then we can say curly braces this that 只是暂时在这里做一个段落，然后我们可以说大括号
props count all right so here we go and there we go we can see it there you go 道具计数没问题，所以我们可以走到那里，我们可以看到它，然后您就可以走了
awesome so let me explain this whenever we use these curly braces we're 太棒了，所以当我使用这些花括号时，让我解释一下
basically executing JavaScript inside of the HTML code here and this dot props 基本上在HTML代码中执行JavaScript，这是点道具
right is how we fetch data passed down to this component so we say this that 正确的是我们如何获取传递到该组件的数据，所以我们这样说
props that account is this right here so we said account this say that account 道具就是这个账户，所以我们说这个账户，说那个账户
gets turned into this props that account okay 被变成这个道具就可以了
so props is just short for properties I believe and this is how you like you 所以道具只是我相信的属性的缩写，这就是你喜欢的方式
define the components properties like you add a new property here and you saw 定义组件属性，就像您在此处添加新属性一样，
props here whenever we set up the constructor as well alright so now the 每当我们建立构造函数时，道具就在这里，所以现在
next thing we want to do is add a better we want to render the component out on 接下来我们要做的是添加一个更好的我们想要渲染的组件
the page now the next thing we want to do is render the account on the page in 现在，我们要在该页面上进行的下一步是在
a more pleasing way so right now you can barely see it's the same text color so 一种更令人愉悦的方式，所以现在您几乎看不到相同的文本颜色，因此
I'm gonna basically delete this and add some markup that looks like this okay 我基本上要删除它并添加一些看起来像这样的标记
so this is basically just creates a unordered list with bootstrap that's 所以这基本上只是创建一个带有引导程序的无序列表
going to make it look a lot nicer all right so let's save that you can just 会让它看起来更好，所以我们保存一下，就可以
you can just fetch this from the code down in the description below if you 您可以从下面的说明中的代码中获取该代码，如果您
don't want to code this out step-by-step alright so there you go we can see the 不想一步一步地编写代码，所以您可以继续浏览
account here looks a little bit nicer alright and then the last thing we want 好，这里的帐户看起来更好，然后我们想要的最后一件事
to do is add this icon here alright so this is the identical that's going to 要做的就是在此添加此图标，所以这与将要
correspond to the account itself okay so how do we do that well if you look at 对应于帐户本身，好吧，如果您看一下，我们该怎么做呢？
the identic on library that we saw at the very beginning it shows us how to do 我们在一开始就看到的关于图书馆的标识向我们展示了如何做
that so um it shows you how to do it basically 嗯，它向您展示了基本的操作方法
you just pass it a hash in this case this is going to correspond to the 您只需将其传递给哈希，在这种情况下，这将对应于
etherium address and then you know here you go you can see this image with the 以太坊地址，然后您就知道您要走了，您可以看到带有
width height and then for the source attribute it's going to have this data 宽度高度，然后对于source属性将具有此数据
alright and it's gonna we're gonna concatenate the string and pass in the 好了，我们将连接字符串并传递
data this way so I'm gonna kind of create a better version of this like 这样的数据，所以我会创建一个更好的版本，例如
this that we're gonna use in our application so don't don't worry if like 我们将在应用程序中使用的这个，所以不要担心，如果喜欢
you don't fully understand what's happening with this library that's okay 您不完全了解该库的运行情况，这是可以的
you can just kind of go back and reflect upon this later try to get a better 您可以回去考虑一下，稍后再尝试以获得更好的结果
understanding of it so for now I'm going to do is just import the identic on 了解它，所以现在我要做的就是将identic导入
library inside this component alright like this and then I'm going to create a 像这样的组件内部的库，然后我将创建一个
way to list it out the page so just below the ending Li tag before the 将其列出在页面中的方式，因此位于
ending UL tag I'm gonna put this in here alright so basically if the account 结束UL标签，我要把它放到这里，基本上，如果该帐户
exists that we want to show this image alright and this image is going to be 存在我们想要显示该图像好并且该图像将是
the identity on so we give it a width a height and then we create this source 标识，所以我们给它一个宽度一个高度，然后我们创建这个源
attribute alright that looks like this alright and then we pass in the account 看起来不错的属性，然后我们传入帐户
this dot props that account alright let's go back to page and see if 这个点说明该帐户不错，让我们返回页面，看看是否
it worked alright it did work it looks kind of funny so let's just fix it so we 它工作正常，看起来确实很有趣，所以让我们对其进行修复，以便我们
need to move this inside the Li so sorry about that let's try it again and boom 需要在Li里面移动它，对此感到抱歉，让我们再试一次
there we go awesome it worked this looks just like our just 在那里，我们变得很棒，它看起来像我们一样
like our finished product which I accidentally just closed it's a very 就像我偶然关闭的成品一样，
cool so basically does is it takes your aetherium address and then it creates 很酷，所以基本上是这样，它需要您的etherium地址，然后创建
this icon and you know if we change accounts in meta mask you'll see the 此图标，您知道如果我们在元掩码中更改帐户，您会看到
account change refers to page and boom there we go we get a new identity con 帐户更改是指页面和繁荣，我们去了，我们得到了新的身份验证
alright so that's it for this video this part of the tutorial series you know 好了，就这个视频而言，这是您知道的系列教程的一部分
we've connected the application to the blockchain we've wired up our web 我们已将应用程序连接到区块链，并连接了网络
browser to talk to the blockchain we've the account we've loaded the balance 浏览器与区块链进行对话，我们已经拥有已加载余额的帐户
we've learned about react Jas you've gotten a lot in this section right so 我们已经了解了有关React Jas的知识，您在本节中已经学到很多东西，所以
congratulations for making it this far so in the next video what we're going to 恭喜您取得了如此远的成就，因此在下一个视频中我们将要
do is continue building out the project and implementing the BI tokens feature 要做的是继续构建项目并实施BI令牌功能
that we created with the smart contracts on the backend now we're going to wire 我们在后端使用智能合约创建的内容
up the client-side application to actually talk to those smart contracts 客户端应用程序与这些智能合约进行实际对话
we'll see you talk to the smart contracts and purchase the tokens all 我们将看到您与智能合约进行对话并购买所有代币
right you know we have created the smart contracts for the east swap exchange we 知道吗，我们已经为东部掉期交易所创建了智能合约，
created a token smart contract and we've connected our website to the blockchain 创建了一个令牌智能合约，我们已经将我们的网站连接到了区块链
now we want to do is actually load these smart contracts into our app so that we 现在我们要做的是将这些智能合约实际加载到我们的应用程序中
can use them all right we want to end up building this and we need the token 可以正确使用它们，我们要最终构建它，我们需要令牌
smart contract and we need the eath swap smart contract to facilitate this you 智能合约，我们需要食堂互换智能合约来帮助您
know buy and sell mechanism that you see here you know the client side website 知道您在这里看到的买卖机制，您知道客户端网站
that we're building right now is our front end and we basically finished the 我们现在正在构建的是我们的前端，我们基本上完成了
back end already and what we're doing right now is essentially just you know 已经是后端，而我们现在正在做的基本上就是您所知道的
connecting the front end and the back end parts of our application all right 正确连接我们应用程序的前端和后端
so the first thing I want to do is go ahead and open up the code and go back 所以我要做的第一件事是继续打开代码，然后返回
to where we were we loaded the account and we loaded the ether balance of this 到我们加载帐户的位置，并加载了以太余额
account all right so we can take out this console logging statement and we 帐户没问题，所以我们可以取出此控制台日志记录语句，我们
want to continue on with this all right we want to load up the smart contracts 想继续进行下去，我们要加载智能合约
into this project so the nice thing is we can we can just import the smart 进入这个项目，所以好事是我们可以导入智能
contracts directly from our truffle project right that's one of the reasons 直接从我们的松露项目中签合同是原因之一
that we have this special setting instead of our truffle project to change 我们有这个特殊设置而不是我们的松露项目来更改
where the smart contracts are basically we can take this eath swap file and 基本上是智能合约所在的地方，我们可以使用这个Eath交换文件，
import it into this app Tijs file to use the smart contract directly with web 3 将其导入到此应用程序Tijs文件中，以直接在Web 3中使用智能合约
j/s okay so basically this is just an ABI right here that you see this is a j / s好的，基本上，这只是一个ABI，在这里您会看到这是一个
JSON array that describes the functions of the smart contract you just tells you JSON数组，描述您刚刚告诉您的智能合约的功能
how all the code works basically and we can use this ABI to create a JavaScript 所有代码基本上如何工作，我们可以使用此ABI创建JavaScript
version of the smart contract so that we you know call its functions just like we 版本的智能合约，这样我们就知道调用它的功能就像
didn't set our tests but inside the web application all right the front-end 没有设置我们的测试，但是在Web应用程序内部的前端
application so I show you how to import that to the project like this you just 应用程序，所以我向您展示如何将其导入到像这样的项目中
say 'i swamp i'll stood above the nav bar actually alright he swapped it's an 说“我沼泽我会站在导航栏上方，好吧，他换了，这是
import capital e capital swap right just like the smart contract from dot dot 就像点对点智能合约一样，具有进口资本和资本互换权
means go up a directory right we're here go up or directory and then go to the 意思是上一个目录，我们在这里上一个目录，然后转到
api's folder and then take eath swap out of it json and assigned to this variable api的文件夹，然后从其json中取出eath交换并分配给此变量
and then likewise we'll do the same thing for our token so just above each 然后同样地，我们将对令牌执行相同的操作，因此在每个令牌的上方
swap will import the token now technically this entire file isn't an swap从技术上讲现在将导入令牌，整个文件不是
ABI so this isn't necessarily the best name for this but you get the idea all ABI，所以这不一定是最好的名字，但是您全都知道了
right the ABI is technically inside this big JSON object but that's okay now that 正确，ABI从技术上讲就是在这个大的JSON对象中，但是现在可以了
we have both of these imported we can use them inside ablow blockchain data so 我们都导入了这两个数据，因此可以在大量的区块链数据中使用它们，因此
right here what we want to do is create a JavaScript version of the smart 在这里，我们要做的是创建一个JavaScript版本的smart
contract so that we can you know fetch we can use we can interact with it we 合同，这样我们就可以知道我们可以使用我们可以与我们进行交互
can call its functions like balance of we can do all kinds of stuff so first 可以调用它的平衡之类的功能我们可以做各种事情，所以首先
we'll start with the token and the main thing we want to do is get the token 我们将从令牌开始，我们要做的主要事情是获取令牌
balance so that we can show it on the page like this right here all right so 平衡，这样我们就可以在这里像这样在页面上显示它，这样
we've got the ABI for the token here but let's see how we create a JavaScript 我们在这里有令牌的ABI，但让我们看看如何创建JavaScript
version of it well we do with the web 3 library and if we go look at the web 3 它的版本很好，我们使用Web 3库，如果我们去看一下Web 3
documentation they tell us how to create a new web 3 contract like this all right 他们告诉我们如何创建新的Web 3合同的文档
you just say new web 3 eath contract and then you need two pieces of information 您只说新的Web 3 Eath合同，那么您需要两条信息
you need the JSON interface and you need the address all right so I'm literally 您需要JSON接口，并且需要正确的地址，所以我的意思是
just going to copy and paste this inside if you're alright so so new web 3 eath 只要您没事就可以将其复制并粘贴到内部，所以新的web 3 eath
contract and you need the ABI any of the address so we'll just say Const 合同，并且您需要ABI的任何地址，所以我们只说Const
token equals this and we need constant a bi we need to fill that in and then 令牌等于这个，我们需要一个常数bi，我们需要填写它，然后
use a conscience we need to fill that in all right a bi 使用良心，我们需要将其填满
address so those are two pieces information we need in order to create a 地址，所以这是我们需要创建的两个信息
JavaScript version the smart contract so why is that well the ABI tells us you JavaScript版本是智能合约，那么ABI为什么这么好告诉我们
know how the smart contract works what the functions are basically just tells 知道智能合约的工作原理这些功能基本上可以说明
us what the code looks like all right and then the address is where that smart 我们的代码看起来不错，然后地址就是那个聪明的地方
contract is on the blockchain so you can multiple you could you could have 合约在区块链上，所以您可以拥有多个
multiple smart contracts that have the same ABI but you want to tell it the 具有相同ABI但您想告诉它的多个智能合约
address of the specific smart contract that you want to use okay 您要使用的特定智能合约的地址
so I'll show you how to get all that information we'll start with the ABI so 因此，我将向您展示如何获取我们将从ABI开始的所有信息，
if you look inside this ABI is file token JSON you know when we imported 如果您查看此ABI是文件令牌JSON，就知道我们导入时
this right here we imported this entire JSON object so we can literally just get 在这里，我们导入了整个JSON对象，因此我们可以从字面上获取
the ABI right here this ABI will just equal token token to ABI and then the ABI就在这里，这个ABI将等于ABI的令牌令牌，然后
address will be inside of this file so if you look inside of here here's ABI 地址将在此文件中，因此，如果您在此处查看，这里是ABI
let's look at the networks all right so there's just like there's a bi key 让我们看一下网络，就好像有一个双向密钥
there's also a network key so this will tell you the different networks that the 还有一个网络密钥，这样可以告诉您不同的网络
smart contracts deployed to on the blockchain 将智能合约部署到区块链上
and we're specifically gonna look at this network this is ganach 5777 like if 我们将专门研究这个网络，这是ganach 5777，就像
you go to a ganache you can see here 5777 right here all right it's the same 你去ganache，你可以看到这里5777就在这里好吧，是一样的
ID and you want to find the address so you look inside this file you find ID，并且您想查找地址，以便在该文件中查找
networks this network and then this address alright so we can do that like 网络这个网络，然后这个地址好吧，所以我们可以这样做
this we can basically just say token got networks 我们基本上可以说令牌获得了网络
literally just pass in 5777 all right and then get the address and then that 从字面上看，只需传入5777，然后获取地址，然后
would be the token and we can say console.log token go back to the web 将是令牌，我们可以说console.log令牌返回到网络
browser and there we go there it is there's the lab 3 contract so now what I 浏览器，然后我们去那里，那里有实验室3合同，所以我现在
want to do is make this code a little more robust because this is really 要做的是使此代码更健壮，因为这确实
brittle like we don't want to just hard code this address here or we don't want 脆弱，就像我们不想在这里硬编码该地址，或者我们不想
a hard code the network like if we change networks we want this to be a 网络的硬编码，例如，如果我们更改网络，我们希望它成为一个
dynamic all right so what I'm gonna do is actually get the network ID that 动态好吧，所以我要做的实际上是获取
we're currently connected to in meta mask so we do that like this we just say 我们目前已连接到元掩码中，因此我们只能这样说
network ID load network ID all right so wait web 3 eath net get ID this will 网络ID加载网络ID没问题，所以请等待web 3 eath net get ID这将
return 5777 because we're connected to ganach say network ID all right and then 返回5777，因为我们已连接到ganach，然后说“网络ID”，然后
go back to the project sorry looks like we had a type over here all right boom 回到该项目，对不起，看起来我们在这里过得很好
there we go still works awesome so now we want to do is refactor this little 我们去的地方仍然很棒，所以现在我们要做的就是重构这一点
more so potentially this could be this could be empty so we don't necessarily 更可能是因为这可能是空的，所以我们不一定
want to call address we might get undefined on this so we'll do this we'll 想要致电我们可能对此未定义的地址，所以我们将这样做
say we'll refactor this to call it token token data and then we'll say you know 说我们将对其进行重构以将其称为令牌令牌数据，然后我们说您知道
if token data because it may not exist if we change networks all right we'll 如果令牌数据，因为它可能不存在，如果我们更改网络，我们会
just do something here if the token data exists the address will just be token 如果令牌数据存在，请在此处做一些事情，地址将只是令牌
data dot address all right so yeah pause for a second and just kind of let that 数据点地址没问题，所以暂停一秒钟，只是让
sink in there further we don't necessarily need to do address here 进一步陷入困境，我们不一定需要在这里解决
anymore we can just put token data address here because that's pretty easy 现在我们可以在这里放令牌数据地址，因为这很容易
to read all right then finally we don't need to 阅读所有内容，那么最后我们不需要
use this a bi variable because that's pretty self-explanatory - and then we 使用这个bi变量，因为这很容易解释-然后我们
put that here okay awesome so finally if the tokens not it's not 把它放在这里好极了，所以最后如果令牌不是它不是
deployed to the network we say window alerts token contract not deployed to 我们说窗口警报令牌合同没有部署到网络
detected network all right so save that go back here and boom there 检测到网络没问题，请保存，然后返回此处并在此处进行繁荣
we go we see it log to the console so now let's see if our alert works let's 我们继续，我们看到它记录到控制台，所以现在让我们看看我们的警报是否有效，让我们
go to main net and boom there we go token contract not deployed to detect a 去主网和繁荣那里，我们去令牌令牌未部署来检测
network if we click go back to ganache all right click refresh awesome works 网络，如果我们单击返回到ganache，请单击右键，刷新令人敬畏的作品
perfect all right so we're getting somewhere 完美吧，所以我们到了某个地方
we'll just say load token here and now we want to do is store the token in the 我们只是在这里说加载令牌，现在我们要做的就是将令牌存储在
state so down here we'll just say let's do like this so just below it count say 这样说，在这里，我们只说让我们这样做，所以在它下面算是说
token equals this empty object alright and then I'll see here token data token 令牌等于这个空对象，然后我将在此处看到令牌数据令牌
will say this set state and then we'll say token goals token and remember we 会说这个设定状态，然后我们说令牌目标令牌并记住我们
can do this shorthand like this all right and then now we want to do is you 可以像这样做这样的速记，然后我们要做的就是你
know refresh the page make sure everything we're properly you have no 知道刷新页面，确保一切正常，您没有
issues now we want to do is actually fetch the balance so we'll we'll do that 我们现在要做的问题实际上是获取平衡，因此我们将做到这一点
just waiting the test like this we'll say let token balance this will be the 只是像这样等待测试，我们会说让令牌平衡这将是
balance of the actual user who's connected so we want to load this 已连接的实际用户的余额，因此我们要加载此余额
balance right here so you already have this information and now we want to do 在这里保持平衡，因此您已经拥有了这些信息，现在我们要做
this okay you know we got the eath balance here so here's eath balance now 好的，你知道我们这里有食堂平衡，所以现在是食堂平衡
we're gonna do token balance co8 token right because we 我们要正确进行代币余额co8代币，因为我们
able to talk to the smart contract now we can call its functions we say token 能够与智能合约对话，现在我们可以调用它的功能，即令牌
methods balance of all right let me say this that state count right we're trying 方法平衡的所有方法，让我说这就是我们正在尝试的状态计数
to get the balance of the person who's connected to the blockchain right now 获得现在连接到区块链的人的平衡
with meta masks and then finally we can't just do this we also have to say 与元掩码，然后最后我们不能只是做到这一点，我们还必须说
call all right and then we'll say console.log token balance and token 调用，然后我们将说console.log令牌余额和令牌
balance I'll also set the state this set state took in balance and we'll do two 平衡我还将设置该平衡状态的状态，我们将做两个
string and same here we'll do two string all right so let that sink in and then 字符串和这里相同，我们将正确处理两个字符串，所以让它沉入然后
finally we're going to do a default token balance here just below each 最后，我们将在每个下方的位置进行默认令牌余额
balance say zero okay so let's refresh the page and see if it worked 平衡说零好吧，让我们刷新页面，看看它是否有效
all right there we go token balance is zero that's actually what we expect 好吧，我们去代币余额为零，这实际上是我们期望的
because this person hasn't purchased any tokens yet from the eath swap exchange 因为此人尚未从Eath交换交易所购买任何代币
so now really quickly I want to talk about this right this call right here 所以现在我真的想快速地谈谈这个电话
so essentially like you have to do call whenever you're fetching information 因此基本上就像您在获取信息时都必须打电话
from the blockchain there's two types of methods in webs 3 there's call methods 在区块链中，网络中有两种方法3调用方法
which you can see here and then there's send methods okay so call methods all 您可以在这里看到，然后有发送方法，所以调用方法全部
they do is fetch information from the blockchain you know actually create any 他们所做的是从您知道实际上创建任何区块链的区块链中获取信息
transactions so you you have to use call whenever you do that all right 交易，因此您必须随时使用通话
so whenever you send that's when you're actually signing transactions and 因此，每当您发送邮件时，您就在实际签署交易时
putting new data on the blockchain and you have to pay gas so that's when you 将新数据放在区块链上，您必须支付汽油费，这就是您
call send after those functions which we'll see later in the tutorial but I 在我们稍后将在本教程中看到的那些函数之后调用send
want to just make a mention of that while we're here that's why you have to 只想在我们在这里提及这一点，这就是为什么您必须
do call on the end of this right here this just returns the function that's 不要在此结束时调用，这只是返回
going to get executed with its arguments and this actually executes sit but it 要使用其参数执行，这实际上执行了坐姿，但是它
just reads information and doesn't actually write any information right ok 只是读取信息而实际上没有写任何信息好
so I'm gonna take this away so we've loaded the token we've loaded the token 所以我要拿走这个，所以我们已经加载了令牌，我们已经加载了令牌
balance next thing we want to do is load up swap okay so it's very similar 平衡我们接下来要做的是加载交换好，所以非常相似
operation we can just literally copy and paste this and modify it 操作我们可以从字面上复制并粘贴并修改它
instead of load token we can say load eath swap okay so we don't need the 代替load token，我们可以说load eath swap还可以，所以我们不需要
network ID already got that but instead of token data let's just change this 网络ID已经知道了，但我们只需要更改它，而不是令牌数据
eath swap data and this will be e swap alright and this will be e swap do this Eath交换数据，这将是e交换，这将是e交换，请执行此操作
and this and then I'll see your token this would be e swap and then we don't 然后，我将看到您的令牌，这将是e交换，然后我们不
need to load the balance all we need to do is load the smart contract okay 需要加载余额我们需要做的就是加载智能合约
so let's see here I swap data is this alright you swap you swap let's just 所以让我们在这里看看我交换数据是这样吗？
console law let's let's do this next sorry II thought equals you know empty 控制台法让我们来做下一个对不起II认为等于您知道是空的
object here and then finally let's just do a console log yes state eath swap 对象在这里，然后最后让我们只做一个控制台日志yes状态
make sure worked all right there we go there's e swap contract so that's pretty 确保一切正常，我们去了电子掉期合约，这很漂亮
easy so you know it took whatever to get this going and to understand it but you 很容易，所以您知道花了一切时间才能理解它，但是您
know it makes it a lot faster the second time whenever you load the second smart 知道每次加载第二个智能设备时，第二次运行速度会大大提高
contract it's can you just follow the same pattern alright so that loads both 收缩，是否可以遵循相同的模式，以便同时加载
smart contracts into the project now the next thing we want to do is create the 智能合约进入项目，我们接下来要做的就是创建
user interface that we see here so we can start filling out the information 我们在此处看到的用户界面，以便我们可以开始填写信息
and then wire up the by tokens function okay so we're gonna create this layout 然后将by tokens函数连接起来，好了，我们将创建此布局
alright and then we're gonna create a way to fill in the balance and then 好吧，然后我们将创建一种方法来填补余额，然后
we'll actually wire up the buy and sell alright so what I want to do now is go 我们实际上会连接好买卖，所以我现在要做的是
ahead and start adding more conscious sorry more content to the page whole do 向前并开始向页面添加更多的自觉对不起，更多内容
is create a new component alright and I'll see your hope sorry hit don't save 正在创建一个新组件，我会看到您的希望，对不起，不要保存
is here a new file new file we'll call this main J s 这是一个新文件，我们将其称为主文件J
capital M okay so we have app digests now we're gonna have a main bjs and 大写M好吧，所以我们现在有应用摘要，我们将拥有一个主要的bjs，
we're gonna do is just copy well let's do it this way yeah let's just copy the 我们要做的就是复制好，让我们这样做吧，是的，我们只是复制
basics here all right and then paste it in here we'll take out all this stuff 好的这里的基础知识，然后将其粘贴到这里，我们将取出所有这些东西
all right we're just literally taking all this away and then taking out all 好吧，我们只是从字面上拿走所有这些，然后拿走所有
this and when you can have a render function alright and then I take this h1 这个，当你可以有一个渲染功能，然后我把这个h1
right here and you this and then put it in here and take out all the rest of the 就在这里，然后把这个放到这里，然后取出其余的
code so you just have this one div all right 代码，所以您只需要一个div
and then you this will say id equals content all right instead of app we'll 然后您会说id等于内容，而不是app，我们会
call this main so there's gonna be our main component alright and then inside 叫做这个主要的，所以我们的主要组成部分会好，然后在里面
of here we'll import the main component so p2 the navbar say main all right and 在这里，我们将导入主要组件，因此导航栏上的p2会说main正确，
we'll render this out on the page like this instead of hello world to say main 我们会像这样在页面上渲染出来，而不是用hello world来表示main
all right make sure still works boom there we go awesome so there's a there's 好吧，请确保仍然可以正常使用，然后再去那里，我们很棒
a one big reason that I want to do this all right so you know whenever we're 我想正确执行此操作的一个重要原因，所以无论何时我们
loading up all this data here it takes a while and we don't want to show content 在这里加载所有这些数据需要一段时间，我们不想显示内容
on the page until it's finished okay so we want to have a basic loading screen 在页面上，直到完成为止，所以我们想要一个基本的加载屏幕
whenever the app is you know loading up data and we can do that like this we can 只要您知道该应用程序正在加载数据，我们就可以像这样进行操作
just tell it that it's loading and when it is loading will show a loader and 只需告诉它正在加载，加载时就会显示一个加载器，
when it's not loading will show the main so we'll do that like this all right so 当它不加载时将显示主要内容，所以我们会像这样正常进行
we'll say let content all right this will say if well actually us do this 我们会说让内容没问题，这会告诉我们是否真的可以做到这一点
select content and then let loading equals true right so if loading and then 选择内容，然后让加载等于true正确，所以如果加载然后
say this else right so basically we'll take this away 说这是正确的，所以基本上我们将把它拿走
well see this so if if it's loading will say content equals this we're gonna 很好看这个，所以如果它正在加载将说内容等于这个，我们将
create a paragraph that just says you know hey I'm loading it alright like 创建一个段落，说你知道，嘿，我正在加载它，就像
this a paragraph ID loader class name text center loading right the next if 这是一个段落ID加载程序的类名，文本中心将在下一个右侧加载
it's not loading will say content equals the main component that we just created 它不是加载将表示内容等于我们刚刚创建的主要组件
so I'll just copy this put it here alright so the apps loading show the 所以我将其复制到这里好好让应用加载显示
loader it's not loading show the content alright and then in react we can use 加载程序，它不加载，显示内容没问题，然后在反应中我们可以使用
curly braces but the content here alright so now when i refresh the page I 花括号，但这里的内容还可以，所以现在当我刷新页面时
should just see the loader because it's you know just hard coded to true alright 应该只看到加载程序，因为它知道您只是硬编码为正确的
so yeah there's the loader and if we make it false all right boom there we go 所以是的，这里有装载机，如果我们把它弄错了
hello world so now we take the next step and actually store the loader value into 您好世界，所以现在我们进行下一步，然后将加载程序的值实际存储到
state so we can go down here and say loading alright say true and then 声明，以便我们可以在这里说加载好，再说true，然后
instead of this loading we can say you know this state that loading save it go 而不是这种加载，我们可以说您知道这种状态，即加载保存
to the page loading is true alright girls let's say a false and I'll show 到页面加载是正确的好女孩让我们说一个错误，我将展示
their page awesome yeah so true again so we want the default state to be that 他们的页面很棒，是的，再次如此，所以我们希望默认状态是
loading is true so we want to tell the app when loading is finished so we do 加载是正确的，所以我们想告诉应用程序加载完成的时间，所以我们
that right here basically once all this stuff's done we just do this set state 基本上在这里，一旦完成所有这些工作，我们就执行此设置状态
loading pulse so now it'll update dynamically and there you go yeah boom 加载脉冲，所以现在它将动态更新，然后就可以了
there you go so you'll see the loader for just a second and whenever all the 你去那里，所以你会看到装载机只有一秒钟，每当
blockchain date is loaded it'll show hello world on the page awesome so 区块链日期已加载，它将在页面上显示您好世界，因此
that's you know a really great step in the right direction that's going to help 那就是您知道朝着正确方向迈出的非常重要的一步，它将为您提供帮助
us build this application in a much better way and we'll do now is continue 我们以更好的方式构建此应用程序，我们现在要做的是继续
on creating the layout inside this main component so we're kind of done inside 在这个主要组件内部创建布局，所以我们在内部完成了
this file for a little while we're going to 这个文件有一段时间，我们将
on this to build layout now inside of this main digest component what I'm 现在我要在这个主要摘要组件中建立布局了
gonna do is go ahead and just paste in some predefined template code to get 要做的就是继续，只需粘贴一些预定义的模板代码即可
started really fast it would take a really long time to code all this out 起步非常快，将所有这些代码编写起来将花费很长时间
step-by-step it's really just HTML code I don't want the focus of this tutorial 分步介绍，实际上只是HTML代码，我不需要本教程的重点
to be you know how to write HTML I wanted to be more about blockchain so 成为您知道如何编写HTML的我想对区块链有更多了解，
I'm gonna just take this out and then paste this in you can you know you can 我要把它拿出来然后粘贴到里面，你知道吗
check out this point in the project in the in the linked in the description 在说明中的链接中检查项目中的这一点
below to get this if you want to so I'll just paste this in like this alright and 如果您愿意的话，请在下面获取，这样我就可以像这样粘贴它了，
then really quickly just see what was generated all right boom there we go so 然后真的很快就看到产生的一切了。
here's our basic template it's looking a lot closer to what we see here just a 这是我们的基本模板，看起来更接近我们在这里看到的内容
few things we'll need to adjust but you can see basically you know we got a card 我们需要调整的几件事，但是您基本上可以看到您知道我们有一张卡片
here in the card body and then we've got the input for the balance well wire this 在卡体内，然后我们得到了平衡井的输入
up in a second the input for the our started output value and the exchange 在一秒钟内输入我们开始的输出值和交换
rate and then the button to swap the tokens all right and then we've got a 率，然后可以正确交换令牌的按钮，然后我们有一个
form that shows us how to do that all right 表格向我们展示了如何做到这一点
no sorry that allows us to do that so let's just remove some of this space all 抱歉，我们可以这样做，所以让我们删除所有这些空间
right it's looking better go safe so the next thing we want to do is go to the 正确，这看起来更好，请放心，所以我们接下来要做的就是
app that J's file I'm sorry the main yeah so good apt is and let's do this J档案的应用程式，很抱歉主要的原因是，让我们这么做
make it wider all right looking kind of scrunched right now we want to make it 扩大它的范围，好吧，看起来有点扭曲，现在我们要使其
widened like this so we'll go to the see this main element here we'll say style 像这样扩大，所以我们将在这里看到这个主要元素，我们将说样式
max width 600 pixels okay just like that yeah so that didn't quite work I wanted 最大宽度600像素就可以了，是的，所以我不想要
to do one more thing instead of D Flex Center let's do ml OTO 做一件事代替D Flex Center让我们做ml OTO
ml or CMR OTO and boom there we go looking a lot closer all right so the ml或CMR OTO和臂杆，我们可以往附近看很多，所以
same width we don't we won't do these buy and sell buttons yet 我们没有的相同宽度我们不会做这些买卖按钮
just gonna focus on the by part okay and then what we want to do now is show the 只是要专注于部分好，然后我们现在要做的就是显示
token images all right so what I'm going to do now is pull the images for the 令牌图像没问题，所以我现在要做的是为
cryptocurrencies into their project you could just download these images from my 加密货币进入他们的项目，您可以从我的网站下载这些图像
github repository you know I've created these locally on 您知道我已经在本地创建这些的github存储库
my computer so you know you could just basically clone the either the completed 我的计算机，这样您就可以基本上克隆完成的
project or you know the the link in the description below for this part of the 项目，或者您知道以下说明中该部分的链接
project but I would just copy and paste the files into your project inside of 项目，但我只是将文件复制并粘贴到您的项目中
the source directory so it's that source I'm just going to drag the eath logo in 源目录，就是我要在其中拖动Eath徽标的源
like this alright and then I'm also going to drag in the token logo like 这样好吧，然后我也要拖入令牌徽标
this source token logo so here we go just token logo and then here's the eath 这个源令牌徽标，所以在这里，我们只使用令牌徽标，然后是食堂
logo all right boom so let's import those into the project inside the inside 徽标繁荣吧，让我们将其导入到内部的项目中
the main dot J's component we're gonna say token logo so inside main jjs we're 主要点J的组件，我们要说令牌徽标，所以在主要jjs里面，
gonna import them both like this boom token logo alright and then eath logo 会像这样的繁荣令牌徽标一样导入它们，然后再导入徽标
like this okay and we'll put them inside of the project see your image see your 这样好了，我们将它们放入项目中查看您的图像查看您的
let's find the first one so here's the one for ether we'll just use some curly 让我们找到第一个，所以这是一个以太坊，我们将使用一些卷曲的
braces and say eath logo and then we'll say source token logo save that go back 大括号并说出Eath徽标，然后我们说原始令牌徽标保存，然后返回
to the page and boom there we go there's the etherium logo and there's the DAP 到页面并开始繁荣，我们去了以太坊徽标和DAP
token logo so we got the exchange right here we got the input now let's put the 令牌徽标，因此我们在这里进行了交换，现在我们得到了输入，让我们将
balances in so we're gonna take the ether balance and the token balance so 余额，所以我们要以太币余额和代币余额，
we can just pass those values down we've already saved them inside of low 我们可以将这些值向下传递，我们已经将它们保存在低
blockchain data so here inside our main component just like we did with the nav 区块链数据，就像在导航中一样，在我们的主要组件中
bar you know we'd be passed on the account we can say you know ether 吧，你知道我们会通过帐户，我们可以说你知道以太坊
balance passing only say either balance equals this state 余额传递仅说余额等于此状态
balance and also for token balance equals this state token balance all 余额，对于令牌余额也等于此状态令牌余额
right so now I'm going to format this code a little bit like this break it up 对，所以现在我要格式化这段代码，像这样分解
into multiple lines that it's easier to read and there we go so now inside of 分成多行，这样更容易阅读，我们现在就在里面
main we can just format the balances and put them on the page like this I'll see 主要，我们可以格式化余额并将其放在这样的页面上，我将看到
here let's put balance so this is for the ether balance we'll say let's just 在这里让我们保持平衡，这是为了以太平衡，我们会说
do the mouths for now just stop props that ether balance save it and the flow 现在做嘴巴只是停止以太平衡保存它和流动的道具
didn't quite work all right so let's see what's going on here oh I see what it is 不太正常，所以让我们看看这里发生了什么哦，我明白了
I said ether balance it should be eath balance okay awesome so we see the 我说以太平衡应该很好，所以我们看到了
balance it's not formatted correctly so let's format it it's currently 平衡它的格式不正确，所以让我们对其进行格式化
displaying the way value let's actually display the ether value or eath value so 显示方式值，让我们实际显示以太值或食值
we just use our helper web 3 utils from way right I'll be doing the tests and we 我们只是从正确的方式使用了helper web 3 utils，我将进行测试，我们
do it like this boom window dot web 3 utils from way 像这样的繁荣窗口点web 3 utils从方式
this dart props to be either balance eath balance eath balance and then 此飞镖道具既可以平衡，也可以平衡，然后
either all right all right there we go it's formatted now we can do the same 要么好吧好吧，我们去吧，它已经格式化了，我们可以做同样的事情
for the token balance let's just do this again and let's do token balance here 对于令牌余额，让我们再次执行此操作，让我们在此处进行令牌余额
and boom there we go still zero that's what we expect so we have it purchased 繁荣的地方，我们仍然要达到零，所以我们购买了它
many tokens yet but when we do buy them we'll see that go up ok so the next 还有很多代币，但是当我们购买它们时，我们会看到它上涨了，所以下一个
thing that we want to do is wire up the user interface that so whenever we 我们要做的是连接用户界面，以便每当我们
actually do this input it shows the amount of tokens we want to 实际执行此输入将显示我们想要的令牌数量
purchase here it does the conversion for us because you know we see 1/8 equals 在这里购买它会为我们做转换，因为您知道我们看到1/8等于
100 app so we do that like this we want to do a non change handler like this so 100个应用程序，所以我们要像这样做，我们要像这样做一个非变更处理程序，这样
basically like I'll show you we go here and find the input so just blow text we 基本上就像我会告诉你我们去这里找到输入，所以只吹文本
can say on change and this is what's going to trigger any time you know we 可以说改变，这就是您知道我们的任何时候都会触发的事情
change the value of that input say event oops there's a console I'm sure it's 更改输入值，例如event oops，有一个控制台，我确定是
like changing right so you'll see what that happens oops looks like a something 喜欢改变，所以你会看到发生了什么事
went wrong here need to know the curly brace all right so now if I change this 出问题了，这里需要知道大括号，所以现在如果我改变这个
one to three you can see this changing happens so basically whenever this 一到三个，您可以看到这种变化基本上发生在每当
changes we're gonna calculate the number of tokens and show it here so yes that's 变化，我们将计算令牌的数量并在此处显示，是的
what the finished product does so it goes one two three and we see the output 成品做了什么，所以变成一二三，我们看到输出
change like this game so basically you're saying whenever if you put in one 像这样的游戏改变，所以基本上你是说只要你放一个
ether we want to see that you're gonna purchase a hundred tokens input output 以太我们想看看你要购买一百个代币输入输出
right here's the conversion and then you would swap to purchase that many so 就在这里，是转换，然后您将交换购买那么多
whatever it changes we're gonna keep track of the value so we do that with 无论它发生什么变化，我们都会跟踪其价值，因此我们做到了
something called a ref and react we just say ref equals input input I hate it 称为ref并作出反应的东西，我们只说ref等于输入输入，我讨厌
when it does that that's really annoying I wish sublime text wouldn't do that say 当这样做确实很烦人，我希望崇高的文字不会那样说
this input equals input okay and then we say Const ether amount equals this input 这个输入等于输入还可以，然后我们说Const ether数量等于这个输入
value to string okay and then we'll say this set state output is equal to e thir 将值设置为字符串还可以，然后我们将设置状态输出等于e
amount times 数量倍
100 all right then we'll say this console.log this state the output okay 100好吧，我们将说这个console.log这个状态输出没问题
so let's go here and say 1 then it kind of bombs here so I doesn't know what 所以让我们去这里说1然后这里有种炸弹，所以我不知道
state is so we need to set the state object just like we did in the parent 状态是，所以我们需要像设置父对象一样设置状态对象
component all right so we can have a special state just for this one like 组件好，所以我们可以为此有一个特殊的状态
this so just like we did in there the component say I'll put a 0 by default 这就像我们在组件中所做的那样，默认情况下我将放置0
and then we'll do you know one two all right there we go is changing we see it 然后我们会知道吗一两个就行了我们正在改变我们看到了
multiplies it to 100 1200 300 yada yada yada awesome very cool okay awesome 乘以100 1200 300 yada yada yada很棒很酷不错很棒
so now let's let's see here let's show that value in the output okay so 所以现在让我们看这里让我们在输出中显示该值
basically the output is a disabled form field that doesn't take any you know 基本上，输出是一个禁用的表单字段，不包含您所知道的任何内容
human input and we can just assigned a value like this so we'll go here we on 人工输入，我们可以像这样分配一个值，所以我们继续
the output she's disabled and just above that we'll say value equals this state 她禁用的输出，正好高于该值时，我们说值等于该状态
output and we can remove this console logging statement here go back to the 输出，我们可以在此处删除此控制台日志记录语句，返回到
app 1 yep there we go so there's a preview of how many will purchase app 1是的，我们去了，所以可以预览有多少购买
awesome so let's remove this console log here and then let's actually wired up to 非常棒，让我们在这里删除此控制台日志，然后将其实际连接到
make the purchase so how we're going to do this is with something called on 进行购买，因此我们将如何进行此操作
submit this is going to be a handler that's gonna fire whenever the form 提交这将是一个处理程序，只要表格
submits so up here we'll just say on submit equals events and then we'll say 在这里提交这么多，我们只说提交平等事件，然后我们说
vent prevent defaults because we don't want the page to change whenever the vent防止默认值，因为我们不希望页面每次更改时
form submit so I'm gonna set console log purchasing tokens alright 表单提交，所以我要设置控制台日志购买令牌
and then let's just do it here click swap and you can see purchasing tokens 然后让我们在这里做，点击交换，您可以看到购买令牌
right log to the console and so it's not doing anything yet we're gonna wire this 正确的日志到控制台，所以它什么也没做，我们要接线
up so essentially we're going to do is call a smart contract function that does 基本上，我们要做的就是调用一个智能合约功能
the buy tokens function that we created you know and then the older videos when 我们创建的购买代币功能您知道，然后是较旧的视频
we did it in the test suite now we want to do that here but we don't really want 我们现在在测试套件中做到了，我们想在这里做到，但是我们真的不想要
to write the code for that inside this particular you know part we want to 为这个特定的代码编写代码，您知道我们想要的部分
actually add it here instead of at that J s because we have access to the smart 实际上将其添加到此处而不是在J处，因为我们可以访问智能
contract inside of here right so essentially what we'll do is just create 在这里签约，所以基本上我们要做的就是创建
a new function that wraps the smart contract function like this alright so 像这样包装一个智能合约功能的新功能
just above render below the constructor well actually let's do it above the 恰好在构造函数下方的渲染上方，实际上让我们在
constructor dude here we'll say buy tokens this one look a little bit 这里的构造函数伙计，我们会说购买令牌，这看起来有点
different from our other functions we'll say equals ether amount all right and 与其他函数不同，我们会说等于以太量，
we'll say what you want to do is call the function a lot like we did with get 我们会说您想要做的就是调用函数，就像我们对get所做的一样
balance all right so a weight you know token methods balance of so we'll say 平衡好吧，所以权重您知道令牌方法的平衡，所以我们会说
this that states that each swap right that's the smart contract okay right 这表明每个交换权利都是智能合约可以的权利
here and we'll say methods they'll say buy tokens all right and then we'll say 在这里，我们会说一些方法，他们会说正确购买代币，然后我们会说
sins all right so remember I said that earlier I talked about call methods and 一切都好，所以请记住我之前说过，我谈到过调用方法和
web 3 versus send methods well this is a send method ok so go back to web three Web 3与发送方法比较好，这是一种发送方法，所以回到Web 3
documentation see send alright yet this this is how you do a method that creates 文档，请参阅发送，但是这就是您执行创建方法的方式
a transaction you have to tell it who's calling it you have to tell it the value 交易，您必须告诉它调用者，您必须告诉它价值
if you're setting in aetherium and etc etc so we'll say send will pass in the 如果您设置的是etherium等，那么我们会说send将通过
user say value I'll say from this state account and will pass in the 用户说出的价值，我会从该状态帐户中说出，并将传入
amount of aetherium that they want to send so they value equals ether value so 他们想发送的以太币数量，所以它们的价值等于以太币的价值，因此
we're going to put in or start ether amount right so e thermal we're gonna 我们将要投入或开始以太量，所以我们要热
pass this into the function and send it in here so when this happens we're gonna 将此传递到函数中并将其发送到此处，以便在发生这种情况时
say this set state loading true all right and then essentially this is gonna 说这个设置状态加载正确就可以了，然后从本质上讲
be asynchronous so we want to wait for it to finish I will say on transaction 是异步的，所以我们要等待它完成，我会在交易中说
hash passing the hash I'm gonna do it or a function here is getting kind of long 哈希传递哈希，我要去做，或者这里的函数变得有点长
sorry hit him well uh set the loading to false so we'll say this set state 不好意思打他，呃，把加载设为假，所以我们说这个设置状态
loading false okay so we could probably like you know do this or something make 加载错误，好吧，所以我们可能希望您知道这样做或某些事情
this little more readable it's kind of silly to but you get the idea 更具可读性对您来说有点愚蠢，但您明白了
all right so it's working all right it's actually you could do this as a 好的，所以它正常工作，实际上，您可以这样做
one-liner let's do that that might be a little cleaner CV so compiles no I 单线运行，这样做可能会使简历更简洁一些，所以编译
didn't work let's just go back and sorry everybody 没有工作，让我们回去对不起大家
all right awesome good enough for now 暂时还不错
actually you know what I'm gonna make this all one line this is starting it 其实你知道我要怎么做这一切，这就是开始
kind of funny it's kind of long but at least it's correct 有点有趣，有点长，但至少是正确的
alright so sorry about that little detour so now we want to do is pass this 好吧，对这个小弯路感到抱歉，所以现在我们要做的就是通过这个
function down to the component how do we do that well we go down here and we say 深入到组件，我们如何做到这一点，我们在这里，我们说
buy tokens equals this step by tokens all right and then now go to main 购买令牌等于通过令牌正确执行此步骤，然后转到主
digests and inside this function we're gonna actually purchase tokens because 摘要，在此功能内，我们将实际购买代币，因为
we have access to that now so let's calculate the amount of meter 我们现在可以访问它，所以让我们计算一下仪表的数量
we want to buy we shall let ether amount say ether amount equals this input that 我们要购买，我们将让以太币数量等于以太币数量
value to string all right that's this input right here we said you 正确的值字符串，这就是我们在这里所说的输入
know this right we take that value is a ether amount equals window dot web 3.8 知道这个权利，我们认为那个值是一个等于窗口点网3.8的以太币数量
ills two-way right ether amount ether and then we say this props dot by tokens 生二元的以太币，然后我们说这个道具点点
in the past Mather Mountain and now we submit this form we should see a meta 在过去的马瑟山（Mather Mountain）中，现在我们提交此表格，我们应该看到一个元
mass confirmation pop-up click sign it and it should purchase so before we do 批量确认弹出窗口点击签名，它应该购买，这样我们就可以
this I hope it works but take note that the etherion balance is 97 the token 我希望它能起作用，但请注意，以太坊余额为97
balance is zero so let's go by you know 200 tokens so we should see our eath 余额为零，让我们通过您知道200个令牌，这样我们就可以看到我们的食堂
balance go down to like 95 point something and our token balance go up to 余额下降到约95点，我们的代币余额上升到
you know 200 so let's click swap and I had a minute mask confirmation pop-up 您知道200，所以让我们单击“交换”，然后弹出一分钟的口罩确认
off screen click confirm and boom there we go awesome so I've got 200 tokens and 在屏幕外单击“确认”并繁荣，我们变得很棒，所以我有200个令牌，
my ether bounds went down so it is working awesome 我的以太界下降了，所以它很棒
so congratulations we've come really far in this tutorial series so far we've got 恭喜，我们在本系列教程中取得了很大的成就
a way to purchase tokens with the client side website you know you can see the 通过客户端网站购买​​令牌的方式，您可以看到
rate calculation here before you purchase it's really nice user 购买前在这里进行费率计算，这是一个非常好的用户
experience you can just sign the transaction actually buy them like this 经验，你可以只签署交易实际上买这样的
so in the next we're gonna create a way to sell tokens all right we'll be able 因此，在接下来的内容中，我们将创建一种可以出售代币的方法，我们将能够
to you know kind of bounce back and force me to buy form in a cell form and 知道您会反弹并强迫我购买单元格形式的表格，
we'll be able to swap them 我们将能够交换它们
so let's go ahead and open up the main component right we got two components so 所以我们继续并打开主要组件，我们有两个组件，所以
far well 3 the apt is this is the you know the one more you do most of the 到目前为止，3是最合适的，这是您知道的一项，您最多要做
work the main component this is the main content I guess I should say this is 工作这是主要内容，我想我应该说这是主要内容
where the the by form currently is and then we have the navbar so let's create 当前by形式在哪里，然后我们有导航栏，所以让我们创建
a new component and we'll call this by form capital B capital F for form jjs 一个新的组件，我们将其通过表单大写字母B大写F称为表单jjs
alright and we'll just copy this main content put it in by form and then we're 好吧，我们将复制此主要内容并按表格形式放入，然后
gonna take the form content all right take all this content all the way the 会采取所有形式的内容，一路走下去
ending form tag and take it out and then take out all this all right 结束表单标签并将其取出，然后将其取出
and inside this return all you should have is the form code all right so do 在此返回中，您应该拥有的就是表单代码，所以可以
form like this all right so we'll change you'll see your main 这样的表格，我们将更改您的名称，
we'll change this to form or by form okay and then yeah eath logo this all 我们将其更改为表格或按表格的形式确定，然后对所有徽标
looks right to me yep all good so now we'll import this 对我来说很好，所以现在我们将其导入
into main so we'll take out eath logo all that kind of stuff say import by 进入主界面，我们将取出食堂徽标，例如import by
form from by form okay and then right here where we have this form let's just 从一个表格开始，然后在这里有这个表格
replace it with the by form all right and now we're gonna pass down all the 可以用by形式替换它，现在我们将把所有
data that we need to the by form right because we have some functions inside of 我们需要的数据，因为我们内部有一些功能
there so basically we'll just say you know by form and then we'll add like 基本上，我们只是说说您知道表格，然后添加
eath balance see this props eath balance okay and then we'll do this I must say 食堂平衡看这个道具食堂平衡好的，然后我们要做到这一点我必须说
token balance this step prop stop took a balance and one more time will do by 代币余额此步骤道具止损取得了余额，并且还会有更多时间
tokens 代币
okay so this is the balance for ether this is the token balance and this is 好，这是以太币的余额，这是代币余额，这是
the buy tokens function so now we should go back to our page and so look the same 购买令牌功能正常运行，因此现在我们应该返回到页面，外观相同
yep this measure still works let's just buy 100 tokens with one ether 是的，这一措施仍然有效，让我们只用一个以太币购买100个代币
let's do decimals just to make sure you know it works properly do 50 tokens with 让我们做十进制只是为了确保您知道它可以正常工作用50个令牌
half an ether and click swap she made a mass pop up click confirm and there we 半个醚，然后单击交换，她弹出一个大众弹出窗口，单击确认，然后我们
go now we have 250 all right so the by form still works we've refactored this 现在，我们有250个权利，所以按表格仍然有效，我们已经重构了
so now we want to do is create a cell form as well all right so I'm just gonna 所以现在我们要做的就是创建一个单元格表格，好，我要
copy this well it's just it this way new file cell form there Jess paste all this 很好地复制它，就是这样，新文件单元格在那里，Jess粘贴了所有这些
code in here and for now let's just take out the form I just say you know div say 代码，现在就让我们取出表格，我只是说你知道div说
cell form alright and then cell form we're just gonna you know have a 单元格形式好，然后是单元格形式，我们将要知道
placeholder so that we can switch in between the forms okay so the by form 占位符，以便我们可以在表单之间切换，所以按表单
still works and it's not the main jjs component what we want to do is track 仍然有效，并且它不是主要的jjs组件，我们要做的是跟踪
the current the current format selected okay so basically we don't need this 当前选择的当前格式还可以，所以基本上我们不需要这个
output here anymore because this got moved to the by form we're gonna say 输出在这里，因为这已经移到了我们要说的by形式
current form and the default value is gonna be by alright and now we want to 当前形式，默认值是好的，现在我们要
do is create some buttons that will actually change this value and when this 要做的就是创建一些按钮，这些按钮实际上会更改此值，
is by then we'll show this and when its cell will show something else but I'll 到那时，我们将显示此内容，并且其单元格将显示其他内容时，我会
do that in a minute so let's handle the difference let's 一分钟内完成操作，让我们处理差异，让我们
let's first import the cell form cell form okay and then we'll do cell form 我们先导入单元格表格，然后再进行单元格表格制作
here alright let's just see it below are here cell form right save it make sure 好吧，让我们在下面看一下吧，这里是单元格形式，保存并确保
still working yeah here's self form so now we can say you know if the current 仍然在起作用，这是自身的形式，所以现在我们可以说，您知道当前
form is by show the by form if the current form is cell then show the self 如果当前表格是单元格，则表格显示依据表格，然后显示自我
form will do that with a conditional statement just like we did and 表单将像我们一样使用条件语句来执行此操作，并且
other component will say let content let's say actually got above the 其他组件会说let内容，比如说实际上超出了
returned let content will say if this state dot current form equals bi else 返回的let内容将说明此状态点当前形式是否等于bi else
all right so if it's by form then kind it's gonna equal this right and let's do 好吧，所以如果它是形式形式的，那就等于这个权利，让我们做
content type over here and if not it's going to be the cell form and we'll say 内容类型在这里，如果不是，它将是单元格形式，我们会说
content this is just like we did another component alright so let's go back to 内容就像我们做了另一个组件一样，让我们​​回到
page and here it is self form so it's not by let's see I've made a typo here 页面，这里是自我形式，所以不是，我在这里打错了
current form all right boom there we go so the current form is by cuz the 当前的形式，好的动臂，我们走了，所以当前的形式是cuz
default now if we say cell it's change alright cell form awesome so we haven't 现在默认，如果我们说单元格改变了，那么单元格的形式很棒，所以我们没有
you know created a cell form just yet this is just a placeholder but we want 您知道刚刚创建了一个单元格表单，但这只是一个占位符，但我们要
to make sure that the state is actually changing that so by alright awesome so 确保状态实际上正在改变，这样很好
now what I want to do is create buttons that actually change this value so we 现在，我要创建的按钮实际上会更改此值，因此我们
can toggle between the by form in the cell form okay so I'm gonna do that like 可以在单元格形式的by形式之间切换，好吧，我要像
this so inside of here you know just above the card when I paste this in here 因此，在此内部，当我将其粘贴到此处时，您就知道卡的上方
boom alright let's go look at on the page there we go looks a lot like our 好吧，让我们来看一下页面，我们看起来很像我们
our the mock-up so this just added some buttons of the page so you know you 我们的模型，所以这只是添加了页面的一些按钮，所以您知道您
could code this out yourself you wanted to or you could just fetch this from the 可以自己编写代码，也可以从
completed project in the description sorry in the description below what this 描述中完成的项目抱歉，下面的描述中这是什么
does is it just adds you know a new div here with two buttons buy and sell all 只是添加您知道这里有两个按钮的新股买卖所有
right and then this little spacer in between alright and we're not quite we 对，然后介于两者之间的这个小间隔，我们不是很清楚
have a little extra space in our final mock-up or on our final version so let's 在我们的最终模型或最终版本中有一些额外的空间，所以让我们
say class name equals MT 3 that's margin top three all right and then boom there 说类别名称等于MT 3，这是保证金前三名，然后在那里繁荣
we go awesome perfect so now what we want to do is click on these buttons and 我们非常完美，所以现在我们要做的就是单击这些按钮，
change the forms right now they don't do anything they just you know sit there 现在更改表格他们什么都不做，只是您知道坐在那里
but it's pretty easy so what we'll do is but add a new row here okay and then 但这很容易，所以我们要做的是在这里添加一个新行，然后
we'll say on click simmer we did unchanged for the by form here unchanged 我们会说点击慢炖时，我们对按表单所做的操作未做任何更改
and we did an on submit here we're gonna do on click so whenever we click the 并且我们在这里进行了提交，因此我们会点击，因此无论何时点击
button will say events it's pretty easy we'll just say this set state current 按钮会说事件，这很简单，我们只说当前的设置状态
form by and then likewise down here well uh let's do this replace this here so 形成，然后同样在这里，嗯，让我们在这里替换它，这样
I'll see you in action bye and so awesome pretty easy so yeah 我会在行动中再见，再好不过了，太好了，是的
we just changed the state value and this reads the state and says if the state 我们只是更改了状态值，它读取状态并说出状态
says the current form is by showed by form and if it's set and show the self 说当前表单是按表单显示的，是否已设置并显示了自己
form okay awesome so now let's let's keep coding out the 形式还不错，现在让我们继续编码
self form because right now it's just this bear form like this okay so let's 自我形式，因为现在只是这种熊形式，好吧，让我们
you know copy all the content that's in the by formats other render function let 您知道通过其他渲染功能复制格式中的所有内容
surprice sorry replace it and we're just gonna do the opposite right so basically 非常抱歉，将其替换，我们将要做相反的事情，所以基本上
put all this inside here here's the old form alright so basically gonna be two 把所有这些放到这里，这是旧表格，所以基本上是两个
by forms right now oops we got a problem let's pass the 现在通过形式哦，我们遇到了一个问题，让我们通过
data down that we need okay for now let's just do this and do the exact same 现在我们需要好的数据，让我们这样做，做的完全一样
data so the form works alright so cell works it looks the exact same that's 数据，因此表单可以正常运行，因此单元格可以正常运行
because it is the exact same and let's change this okay so we're gonna reverse 因为它是完全相同的，让我们更改此方法，这样我们就可以反向
this first let's change the tokens so we'll just do it one by one here first 首先让我们更改令牌，所以我们先在这里一个接一个地做
this should be token balance alright the input is now tokens because they're 这应该是令牌余额好吧，现在输入是令牌，因为它们是
gonna sell them all right and then whenever we're converting the values the 会把它们卖掉，然后每当我们转换价值时，
ether amount should be should be token amount and instead of multiplying it by 以太币数量应为代币数量，而不是乘以
a hundred it should be divided by a hundred right because you sell the 一百应该除以一百，因为您卖出
tokens to buy them 100 all right and then that's the output okay and then 代币可以买100，然后输出就可以了，然后
instead of East logo will say token logo and say DAP it's actually just copy this 而不是East徽标会说令牌徽标并说DAP，实际上只是复制了此内容
do this oops sorry Emma and swap these okay and 这样做对不起Emma并交换这些还可以，
then for the output this will be ether balance or eath balance all right and 然后对于输出，这将是以太平衡或均衡
then I'll do a slow go okay and then exchange rate she we could say you know 然后我会慢慢走好，然后再兑换汇率，我们可以说你知道
100 DAP equals 1/8 and then swap then that should work let's click it sell 100 DAP等于1/8，然后交换然后应该起作用，让我们单击它卖出
yeah there you go so the balance is now 254 tokens and 是的，你去了，所以余额现在是254个代币，
then 95 for ether we see the exchange rate change as well all right boom there 然后以太坊价格为95，我们看到汇率也在变化。
we go so the last thing we want to do is wire up the form submission so I'll see 我们走了，所以我们要做的最后一件事就是连接表单提交，所以我会看到
you like this basically we'll change some values here so instead of ether 您基本上喜欢这样，我们将在此处更改一些值，所以代替以太
mail this can be token amount all right this input value to string all right so 邮件这可以是令牌数量，可以将此输入值字符串化，这样
say cell tokens here and it's gonna blow up because it doesn't know what sail 在这里说细胞令牌，它会炸掉，因为它不知道航行的方向
tokens is or ether amount so they ether amount sorry all right so I'm not sure 代币是或以太币，所以他们以太币对不起，所以我不确定
why cell tokens is we're not calling the function that's why it's not blowing up 为什么单元标记是我们没有调用函数，这就是为什么它没有爆炸的原因
yet all right so now let's change this so don't buy form so go sell tokens here 还好吧，现在让我们更改一下，不要购买表格，所以在这里出售代币
all right for the cell form all right and then finally we actually want to 正确的单元格形式，然后最后我们实际上想要
create a cell tokens inside of here cell tokens equals this cell tokens 在此处创建与该单元标记相等的单元标记
all right and all right it still works that's because we're not calling the 好吧，好吧，它仍然有效，这是因为我们不称呼
function yet and finally we want to create a cell tokens function like this 函数，最后我们要创建一个像这样的单元标记
say cell tokens all right and the cell tokens function is going to 说单元令牌没问题，单元令牌功能将
work a little bit differently so we'll be the token amount it's gonna be the 工作方式略有不同，因此我们将成为代币数量
opposite now this is really the final thing once this works the entire project 相反，这一旦完成整个项目，这实际上是最后一件事
should work but here's a very critical thing I want to go back to the tests and 应该可以，但是这是非常重要的事情，我想回到测试中，
remind you that you know selling tokens is a two-step process sorry there's two 提醒您，您知道出售代币是一个两步过程，很抱歉有两个
functions at play if you go to the contracts actually sleeping test first 如果您先参加实际睡眠测试的合同，则会发挥作用
when I would do sell tokens remember the investor must approve the tokens before 当我要出售代币时，请记住投资者必须先批准代币
the purchase all right because the eath swap token the eat swap exchange 购买可以，因为Eath交换令牌eat交换交换
contract sells it for the investor and the investor must say yes approve the 合同将其卖给投资者，投资者必须说同意
tokens before that happens all right so we have to call this function and 令牌在此之前发生，所以我们必须调用此函数，
then this function so inside abjad yes we'll say this say eat up sorry you swap 然后这个功能，所以在阿贾德里面是的，我们会说这个说吃了抱歉对不起
methods sell tokens actually no no sorry we're not gonna call this on the 方法出售令牌实际上不，不，对不起，我们不会在
exchange we're gonna call them a token first token methods all right and then 交换，我们先将它们称为令牌，然后再调用令牌方法
approve write must be approved first and we want to do the approval to this state 批准写入必须首先获得批准，我们要对此状态进行批准
eath swap to address all right and we want to do the token amount we want to Eath交换以解决所有问题，我们想要执行我们想要的代币数量
say yes you can sell the number of tokens that I'm telling you - all right 说是的，您可以出售我告诉您的代币数量-好的
now we do send we don't do value here we just say from this state on account all 现在我们确实发送了，我们在这里不珍惜，我们只是从这个状态说所有
right then on transaction hash that's okay once that's finished then we sell 然后在交易哈希上完成就可以了，然后我们卖出
the tokens say this state eath sorry eath swap methods sell tokens token 代币说此状态抱歉代币交换方法出售代币代币
amount 量
all right and then send so just like we did here I'm gonna copy this literally 好吧，然后发送，就像我们在这里所做的一样，我要照原样复制
oops sorry 哎呀，对不起
and then we copy this alright and then we set the state loading false all right 然后我们复制此行，然后将状态设置为false
now let's give it a try so let's go back to the page here here's the BIOS make 现在让我们尝试一下，让我们回到页面，这里是BIOS
sure it still works let's buy you know 100 tokens click swap minute mask will 确保它仍然有效，让我们购买100枚代币，然后单击“交换分钟”掩码
pop up click confirm all right so there we go we got a hundred more tokens now 弹出单击确定，好吧，我们走了，我们现在有一百多个令牌
let's go sell those hundred tokens one hundred should get one ether back click 我们去卖掉那一百个代币一百应该得到一个以太币
swap oh we got a problem alright so this step props that sell 交换哦，我们有问题了，所以这一步道具卖了
tokens is not a function says in the self forum alright let's just trace it 令牌不是自我论坛中所说的函数好吧，让我们对其进行跟踪
all the way down so sell tokens is here alright and then sell tokens is here 一路下跌，所以这里出售令牌，然后再出售令牌
this sell tokens that looks right so now let's go to the main components ah sell 这个卖出的代币看起来不错，所以现在让我们看一下主要组件
token that's the problem sell token no s let's just keep going 这就是问题的代币出售代币没有，让我们继续前进
though make sure so sell form I'll see your let's go down to the self 虽然请确保以这种形式出售，但我会看到您让我们深入自我
form and say sell tokens alright perfect this docprops/app.xml it's 200 tokens 表格上说出售令牌可以完善此docprops / app.xml，它是200个令牌
and then we should see the balance get out of 350 if it worked so swap so do 然后，如果余额有效，我们应该会看到余额脱离了350，所以可以这样做
you want to spend your DAP yes we do click confirm and then a second 您想花费您的DAP是的，我们点击“确认”，然后再点击一次
confirmation could come up I click on firm and boom there we go 确认可能会出现，我点击公司，然后繁荣就到了
we sold the tokens back our balance went down out of 350 and our ether balance 我们卖掉了代币，我们的余额从350减少到了以太币余额
went back up to 94 alright so there you have it that is the completed project 回到了94好的，所以您已经完成了项目
you have successfully created each swap the instant exchange where you can buy 您已成功创建每个交换的即时交换，您可以在此购买
and sell cryptocurrencies at a fixed price so congratulations you've really 并以固定价格出售加密货币，恭喜您
come a long way in this tutorial series you know we started out from scratch you 在本教程系列中走了很长一段路，您知道我们从头开始
learned about blockchain you learned about how to build smart contracts how 了解了区块链，了解了如何构建智能合约
to work the cryptocurrencies how to build a client-side application and 使用加密货币，如何构建客户端应用程序以及
react yes so yeah take a minute to congratulate yourself you've come really 反应是的，所以花一点时间祝贺自己，你真的来了
far so I'll say there's you know several ways you could get extra credit by 到目前为止，我要说的是，您知道几种获得额外信用的方式
improving on this project maybe you want to turn this into a portfolio piece if 改善这个项目，如果您想将其变成投资组合，
you're trying to become a professional blockchain developer or you just want to 您正试图成为专业的区块链开发人员，或者您只想
show it off to your friends you know you could support multiple tokens on here 向您的朋友炫耀，您知道您可以在此处支持多个令牌
and you could change the tokens that you want to swap of course you'd have to add 您可以更改想要交换的令牌，当然您必须添加
support for that and the smart contracts you could change the redemption rate 支持和智能合约，您可以更改兑换率
where that you know it's updatable maybe like over time you change the price you 您知道它是可更新的，也许随着时间的流逝您改变价格
know you can create a way for the person to take profits whoever created the 知道您可以创建一种方法，使该人可以利用获利者创造利润
smart contract whenever they you know create this like withdrawal the ether 智能合约，只要他们知道就可以创建，例如退出以太币
balance from the exchange like that so there's lots of ways you can you know 这样的交换平衡，所以您可以通过多种方式知道
continue on with this for extra credit for homework but this is definitely a 继续进行此操作，以增加功课的功劳，但这绝对是一个
great start all right so again the final project codes down the link in the 很好的开始，所以最终项目代码再次通过
description below and if you want to take that next step to mastering 下面的说明，以及如果您想进行下一步以掌握
blockchain like let's say you really like this tutorial then I highly 区块链就像我们说你真的很喜欢本教程，然后我非常
recommend that you head on over to DAP anniversary comm for a slash boot camp 建议您前往DAP周年纪念日参加斜线训练营
because inside there I teach you how to build a fully fledged crypto currency 因为在那儿我教你如何建立成熟的加密货币
exchange where you can create buy orders you can create sell orders way beyond 交换您可以创建购买订单的地方，您可以创建销售订单的方式
you know just this simple exchange that you see here alright so as always click 您知道您在这里看到的这种简单交换，因此一如既往地单击
the like button down below and subscribe to this channel if you have already that 下方的“赞”按钮，如果已订阅该频道
really helps these videos get found so that more people can you know benefit 确实有助于找到这些视频，让更多人知道受益
from them and until next time thanks for watching Jap University 从他们那里直到下一次感谢您收看日本大学