简体   繁体   English

Solidity 文档薄荷并发送 function

[英]Solidity documentation mint and send function

Solidity 文档

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.

相关问题 复制 function in mint contract / solidity - Duplicated function in mint contract / solidity 改变铸币率 uint 的 Solidity 语法错误 - Solidity Syntax error with changing mint rate uint 可靠性:调用另一个合约的函数时出错。 错误:发送值时应向构造函数付款 - Solidity: Error when calling a function of another contract. Error: The constructor should be payable when you send value 如何使用 solidity 调用 function 从合同中发送固定数量的以太币? - How to send fixed amount of ether from contract using call function in solidity? solidity 交易错误,如果您发送 value 应该支付调用的 function 并且您发送的 value 应该小于您当前的余额 - solidity transaction error, The called function should be payable if you send value and the value you send should be less than your current balance Solidity:“如果您发送价值,则应支付称为 function 并且您发送的价值应小于当前余额” - Solidity: "The called function should be payable if you send value and the value you send should be less than your current balance" 在另一个合约中调用 function - Solidity - Call a function in another contract - Solidity Solidity Fallback Function Gas 限制 - Solidity Fallback Function Gas Limit 传递函数无法如预期般可靠地工作 - Transfer function not working as expected in solidity Solidity setName 函数编程 (BitDegree) - Programming on Solidity setName function (BitDegree)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM