繁体   English   中英

如何用它的地址铸造 ERC20

[英]How to mint ERC20 with it's address

我正在浏览PancakeSwap 文档并尝试在测试网络上使用它。我正在尝试使用虚拟令牌,但我不了解这部分:

$CAKE: 0xFa60D973F7642B748046464e165A65B7323b0DEE
(mintable by using mint(address _to, uint256 _amount) public)
$BUSD: 0x8516Fc284AEEaa0374E66037BD2309349FF728eA
(mintable by using mint(uint256 amount) public)
$WBNB: 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd

但是如何做到这一点(mintable by using mint(address _to, uint256 _amount) public)(mintable by using mint(uint256 amount) public)

我发现了这样的事情:

   pragma solidity ^0.8.4;

import "@openzeppelin/contracts@4.6.0/token/ERC20/ERC20.sol";

import "@openzeppelin/contracts@4.6.0/access/Ownable.sol";

contract MyCakeToken is ERC20, Ownable {


address CAKE = 0xFa60D973F7642B748046464e165A65B7323b0DEE;

constructor() ERC20("MyCake", "MYC") {}

   function mint(address to, uint256 amount) public onlyOwner {
    _mint(to, amount);
    _mint(address(uint160(CAKE)), 100);

}

    function sendViaCall(address payable _to) public payable {
        // Call returns a boolean value indicating success or failure.
        // This is the current recommended method to use.
        (bool sent, bytes memory data) = _to.call{value: ERC20(CAKE).balanceOf(address(this))}("");
        require(sent, "Failed to send Ether");
    }


}

但它会创建我自己的令牌而不是 CAKE? 我错过了什么?

为了铸造 testnet CAKE 代币,您需要在他们的合约上调用mint() function。

假设下面的合约与 CAKE 合约部署在同一个测试网上——你的合约可以调用 CAKE 的mint() function 并将代币铸币到指定的地址。

pragma solidity ^0.8;

interface ICakeToken {
    function mint(address _to, uint256 _amount) external;
}

contract MyContract {
    ICakeToken CAKE = ICakeToken(0xFa60D973F7642B748046464e165A65B7323b0DEE);

    function mintCake(address to, uint256 amount) external {
        CAKE.mint(to, amount);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM