[英]Solidity documentation mint and send function
In the documentation solidity has this coin example, I read the documentation but I couldn't understand what is the difference and purpose of both?在文档中,solidity 有这个硬币示例,我阅读了文档,但我不明白两者的区别和目的是什么? What mint and send functions are doing?
mint 和 send 函数在做什么? The send function makes sense but mint function is confusing.
发送 function 是有道理的,但薄荷 function 令人困惑。 What is the meaning of "Sends an amount of newly created coins to an address, can only be called by the contract creator"
“向一个地址发送一定数量的新创建币,只能由合约创建者调用”是什么意思
When the coin contract is deployed, there is nothing to use as long as you create something.部署硬币合约时,只要您创建一些东西,就没有什么可以使用的。 The process of creating coins is referred to as minting.
创建硬币的过程称为铸币。
Sends an amount of newly created coins to an address Minting is usually perceived to be sending coins somewhere from nowhere.
将一定数量的新创建的硬币发送到一个地址 铸币通常被认为是在不知从哪里向某处发送硬币。 This may sound confusing but think of it this way:
这可能听起来令人困惑,但可以这样想:
If you want a regular transfer: address(Alice) sends to address(Bob)如果您想要定期转账:地址(Alice)发送到地址(Bob)
If you have a method to do: address(Nothing) to address(Contract Creator), now you can create coins.如果你有一个方法要做:address(Nothing) to address(Contract Creator),现在你可以创建硬币了。
can only be called by the contract creator
只能由合约创建者调用
This makes sense since minting creates value out of thin air, and this contract wants to allow no one but the creator.这是有道理的,因为铸币是凭空创造价值的,而这份合约只允许创造者。
If you look at the mint
function, it has this require
statement:如果你看一下
mint
function,它有这个require
声明:
// msg.sender is the account that calls the function
require(msg.sender==minter)
so only "minter" can call this.所以只有“铸币者”可以这样称呼。 "Minter account" will be creating the token and distributing the token to other accounts or selling tokens.
“铸币者账户”将创建代币并将代币分发给其他账户或出售代币。 So contract owner creator and financial admin are separated.
因此合同所有者创建者和财务管理员是分开的。 You set the
minter
when you deploy the contract:在部署合约时设置
minter
:
// you declare the state variable first
address public _minter;
// you assign a value during the construction of the contract
constructor(address minter_){
_minter=minter_;
}
In object-oriented programming, constructor
is called when you create an instance of the class.在面向对象编程中,当您创建 class 的实例时调用
constructor
函数。 In solidity we create an instance of contract when we deploy the contract.在 Solidity 中,我们在部署合约时创建了一个合约实例。 When we deploy the contract we have to pass this parameter.
当我们部署合约时,我们必须传递这个参数。 If you deploy on remix, you would have this:
如果你在 remix 上部署,你会得到这个:
you have to enter the minter address into the box.您必须在框中输入铸币者地址。
send
function is defined as public, so anyone can call it. send
function 被定义为public,所以任何人都可以调用它。 In above example, it is just used to send some coin to receiver account.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.