PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 22, 2022

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

 September 22, 2022     binance-smart-chain, blockchain, ethereum, pancakeswap, solidity     No comments   

Issue

i am going through PancakeSwap docs and trying to use it on test net.I am trying to use dummy tokens but thi section i dont't uderstand:

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

but how to do this (mintable by using mint(address _to, uint256 _amount) public) or (mintable by using mint(uint256 amount) public) ?

I found something like this:

   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");
    }


}

but it creates my own token and not CAKE? What i'm missing?


Solution

In order to mint testnet CAKE tokens, you need to invoke the mint() function on their contract.

Assuming the contract below is deployed on the same testnet as the CAKE contract - your contract can call CAKE's mint() function and mint the tokens to the specified address.

pragma solidity ^0.8;

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

interface IBUSD {
    function mint(uint256 amount) external returns (bool);
}

contract MyContract {
    ICakeToken CAKE = ICakeToken(0xFa60D973F7642B748046464e165A65B7323b0DEE);
    IBUSD BUSD = IBUSD(0x8516Fc284AEEaa0374E66037BD2309349FF728eA);

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

    function mintBUSD(uint256 amount) external {
        bool success = BUSD.mint(amount);
        require(success);
    }
}


Answered By - Petr Hejda
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing