经过一段时间的学习,我写了一些简单的solidity代码,然后我决定把它们部署到区块链上
After a while of learning, I wrote some simple solidity codes, and I decided to deploy them to the block chain.
这里我们选择的环境是
Here's where we're going to choose.
会发现我们的钱包被自动注入了,然后点击确认部署合约
We'll find our wallet automatically injected and then click to confirm the deployment contract.
我理解的Injected Provider 就是从本地的 VM测试环境 切换到 网络的测试环境
Injected Provider, as I understand it, is the testing environment from the local VM testing environment to the network.
部署成功咯
It's a successful deployment.
这没什么难的
It's not that hard.
这个我理解的就是当我们在某个合约中引入另一个合约,并且这个实例化这个合约,那么我们在部署当前合约时就相当于一块部署引入的合约
What I understand is that when we introduce another contract in one contract, and this is an example of the contract, when we deploy the current contract, we're equivalent to a deployment-initiated contract.
部署好合约后,未初始化引入的合约实例时,可以看到,simpleStorage的实例全是0
When a contract is deployed and the case of an introduced contract is not initialized, it can be seen that the example of simpleStorage is all zero.
初始化后
After initialization
那我们就得到一个实际的地址
Then we'll get a real address.
对于一个程序员来说,这真的没啥哈哈,就是函数互相调用
For a programmer, it's really nothing. It's a function calling each other.
关注一下写法,和两个关键字,可以被修改的标识是virtual,覆盖的标识是override
Focus on writing, and two keywords, the markings that can be modified are
通过一个简单的交易合约,我们再来学习一些新的内容
With a simple deal, we'll learn something new.
-
payable
是一个函数修饰符,用于指示函数可以接收以太币。在Solidity中,如果你想让一个函数接收以太币(即在交易中有ether被发送到这个函数),那么这个函数需要被标记为
is a function modifier used to indicate that the function can be received in too much currency. In Solidity, if you want a function to be received in too much currency (i.e. where there is another sent to this function in the transaction), then this function needs to be marked as
-
require
函数是一种用于条件检查的控制结构,常用于验证函数调用的前提条件。如果的条件返回,则当前函数执行会立即终止,所有状态更改都会回滚,且未花费的Gas会被退回。此外,函数可以接受第二个参数作为错误信息,当条件不满足时,这个错误信息会被返回,便于调试。
Function is a control structure used for condition check, often used as a prerequisite for validating a call for the function. If the condition returns, the current function will be terminated immediately, all state changes will roll back and the unspent Gas will be returned. In addition, the function can accept the second parameter as a bug message, which will be returned when the condition is not met, so that the error information can be debuggered.
-
的含义
Meaning
在Solidity中,每个交易都有一个全局变量,它包含了交易的一些重要信息。是其中的一个字段,表示随交易发送的以太币(ETH)数量,以wei为单位(1 ETH=10^18 wei)。常用于处理接收以太币的函数中,以确保正确的金额被发送。
In Solidity, each transaction has a global variable that contains some important information about the transaction. It is a field in which the number of ETHs sent with the transaction is in wei (1 ETH=10.618 wei). It is often used to process the receipt of TT functions to ensure that the correct amount is sent.
先来学一个新的概念
Let's start with a new concept.
来自GPT
From GPT
在区块链和智能合约的上下文中,"data feed"通常指的是从区块链外部世界(off-chain)到区块链内部(on-chain)的数据传输机制。因为智能合约运行在封闭的、去中心化的区块链网络上,它们无法直接访问或验证外部世界的数据(如股票价格、天气信息、货币汇率等)。数据馈送提供了一种解决方案,使得智能合约能够依据外部世界的真实信息来执行逻辑。
In the context of block chains and smart contracts, "data feed" usually refers to a data transfer mechanism from the outside world of the block chain (off-chain) to the inside of the block chain (on-chain). Because smart contracts operate on a closed, decentralized network of block chains, they cannot directly access or validate data from the outside world (e.g. stock prices, weather information, currency exchange rates, etc.). The data feed provides a solution that allows smart contracts to follow logic based on real information from the outside world.
我们在Remix里面打开一下这段代码,这是最新的BTC和USD的转化,没找到ETH
We opened this code in Remix. It's the latest BTC and USD transformation. There's no ETH.
看起来没问题,Solidity不支持浮点数或实数类型,这里的小数位数应该是8位
Solidity doesn't support floating points or real-digit types. The decimal numbers here should be eight.
区块链是一个确定的系统,如果我们想要一些实时的、随机的东西,就需要预言机,chainLink是预言机网络
像我们刚刚实现的就是data Feed 获取外部数据
来自GPT
From GPT
Chainlink允许智能合约安全地访问链下(off-chain)数据,包括通过HTTP请求从外部API获取数据。由于智能合约本身无法直接进行HTTP请求或访问外部服务器,Chainlink通过预言机节点(Oracles)提供了一种机制,使智能合约能够间接地发送HTTP请求并接收响应。这一功能极大地扩展了智能合约的应用场景,使其能够利用外部的世界数据,如天气信息、股票价格、飞行数据等。
Chainlink allows smart contracts to safely access data under the chain (off-chain), including requests for data from external APIs through HTTP. Because smart contracts themselves cannot directly request HTTPs or access external servers, Chainlink provides a mechanism by oracles that allows smart contracts to send HTTP requests indirectly and receive responses. This function greatly expands the application of smart contracts to enable them to access external world data, such as weather information, stock prices, flight data, etc.
Single Word Response | Chainlink Documentation
我们找到这个合约,然后在remix里面打开。这段Solidity代码定义了一个名为的智能合约,利用Chainlink网络从外部API(例如CryptoCompare)获取数据。
We found this contract and opened it inside the remix. The Solidity code defines a smart contract called the "Intelligent Contract ", using the Chainlink network to get data from external API (e.g. CryptoCompare).
在部署这个合约之前,先学习一下Link和ETH之间的区别
Before this contract is deployed, learn the difference between Link and ETH.
LINK:LINK是Chainlink网络的原生代币。Chainlink是一个去中心化的预言机网络,它允许智能合约安全地访问链下数据、支付API调用和执行链下计算。LINK代币用于支付Chainlink网络中的节点操作员,这些操作员为智能合约提供外部数据和计算服务。
LINK: LINK is the original ingenuity of the Chainlink network. Chainlink is a decentralised prophesy network that allows smart contracts to access data under the chain safely, pay for API calls and calculations under the enforcement chain. LINK is used to pay node operators in the Chainlink network, which provide external data and computing services for intelligent contracts. ETH:ETH是以太坊区块链的原生货币。以太坊是一个广泛使用的智能合约平台,允许开发者部署去中心化应用(DApps)和智能合约。ETH主要用于支付交易费用和计算服务费(称为gas),这是在以太坊网络上执行操作(如执行智能合约)的必要成本。
ETH: Ether is the original currency of the Tether block chain. Ether is a widely used smart contract platform that allows developers to deploy decentralised applications (DApps) and smart contracts.
然后我们去Sepolia网络上获取一些link
Then we go to Sepolia and get some link.
我们需要去找到这个地址,然后导入我们的钱包中,这样就可以使用刚刚获取到的link币
拿到了
Got it.
然后如果要运行这个合约,需要从钱包给这个合约发送一点link币,
我们给部署好的合约发送0.2 Link
We send 0.2 Link
调用API查看一下,发现有结果了
Call API and check it out. We've got results.
是一个公共函数,任何人都可以调用它来触发一个Chainlink请求,从指定的URL获取ETH的24小时交易量。
is a public function that anyone can call to trigger a Chainlink request for a 24-hour transaction of ETH from a specified URL.
直接粘贴版
获取ABI代码 github.com/smartcontra…
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论