blockchainsoliditysmartcontractserc20bep20

I'm getting compiler debug error while deploying my erc20 token on etherium testnet


Every time I'm trying to deploy my token contract on the test net, I'm facing this error:

Compiler debug log: Error! Unable to generate Contract ByteCode and ABI Found the following ContractName(s) in source code: SafeMath, Token But we were unable to locate a matching bytecode (err_code_2) For troubleshooting, you can try compiling your source code with the Remix - Solidity IDE and check for exceptions

This is the image of error

This is my code:

//SPDX-License-Identifier: Unlicensed 
pragma solidity ^0.8.7;
library SafeMath {
    function Add(uint a, uint b) public pure returns (uint c) {
        c = a + b;
        require(c >= a);
    }
    function Sub(uint a, uint b) public pure returns (uint c) {
        require(b <= a);
        c = a - b;
    }
    function Mul(uint a, uint b) public pure returns (uint c) {
        c = a * b;
        require(a == 0 || c / a == b);
    }
    function Div(uint a, uint b) public pure returns (uint c) {
        require(b > 0);
        c = a / b;
    }
}

contract Token{
    using SafeMath for uint256;
    string public name = 'MY TOKEN';
    string public symbol = 'MTK';
    uint256 public decimals = 18 ;
    uint256 public totalsupply = 10000000000000000000000 ;
    address owner;
    //5% will go to owner and 5% of transaction will burn
    uint taxfee = 5;
    uint burnfee = 5;
    bool public istransferable = false;

    //bool public ExcludedFromReward = false;


    //exclude addresses from deflation
    mapping(address=>bool) public ExcludedFromFee;
    //mapping(address=>bool) public ExcludedFromReward;
    mapping(address => uint256) public balance;
    mapping(address => mapping(address => uint256)) allowance;
    mapping (address => bool) public _Blacklisted;  

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event OwnershipTransfer(address indexed previousOwner, address indexed newOwner);

    constructor(){//(string memory Name, string memory Symbol, uint Decimals, uint TotalSupply) {
        // name = Name;
        // symbol = Symbol;
        // decimals = Decimals;
       // totalsupply = TotalSupply; 
        owner = msg.sender;
        balance[owner] = totalsupply;//TotalSupply;
        ExcludedFromFee[owner] = true;
         _rOwned[msg.sender] = _rTotal;
    }
    function Balance() public view returns(uint256) {
        return balance[owner];
    }

Solution

  • This is because your safetmath library contains public functions. As mentioned in the Solidity documentation, if your library contains public functions, then the EVM will use a DELEGATECALL to invoke the function. However, if your library contains internal functions, then those functions will be inlined in the bytecode of the contract. So, you have two options:

    1. Change the visibility of your library functions to internal
    2. Deploy the library on the testnet and link it to the bytecode of the contract