0

dear Ethereum community,

I have this problem upgrading a contract from 0.4.19 to ^0.6.0:

    function someFunction(
            uint256 initialSupply,
            string memory contractName,
            string memory tokenSymbol,
            uint256 contractHoldTime,
            uint256 contractHoldMax,
            uint256 contractMaxSupply,
            address contractOwner


        ) public {

        totalSupply = initialSupply; 
        name = contractName;            
        symbol = tokenSymbol;        
        holdTime = contractHoldTime;
        holdMax = contractHoldMax;
        maxSupply = contractMaxSupply;
        owner = contractOwner; 
        balanceOf[contractOwner] = balanceOf[contractOwner].add(totalSupply);
        }

in the last line balanceOf... Indexed expression has to be a type, mapping or array (is function (address) view returns (uint256))

waiting your reply...

Thanks

3
  • How did you define balanceOf?
    – Ismael
    Commented May 17, 2020 at 1:15
  • it inherits from an ERC20 with balanceOf function: function balanceOf(address owner) public view returns (uint256 balance) { return balances[owner]; }
    – Ecofintech
    Commented May 17, 2020 at 1:25
  • Im chaing the whole structure. Adding syntac and parent libraries from OpenZeppelin. maybe I can solve the issue in a while...
    – Ecofintech
    Commented May 17, 2020 at 1:41

1 Answer 1

1

The error means you are trying to use balanceOf as it were a mapping but it is defined as a function instead.

For OpenZeppelin 3.0 if you inherit from ERC20.sol the correct approach to modify a balance is to call _mint():

_mint(contractOwner, totalSupply);
1
  • This solved my issue! Thanks!
    – BiBi
    Commented Feb 26, 2021 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.