0

Here are the errors i'm getting with the code all coming from balanceOf function:

Errors:

TypeError: Data location must be "memory" or "calldata" for parameter in function, but none was given.
--> contracts/Htoken.sol:39:24:
|
39 | function balanceOf(address [msg.sender]) public override view returns (uint256) {
| ^^^^^^^^^^^^^^^^^^^^

TypeError: Invalid array length, expected integer literal or constant expression.
--> contracts/Htoken.sol:39:33:
|
39 | function balanceOf(address [msg.sender]) public override view returns (uint256) {
| ^^^^^^^^^^

Smart Contract Code:

constructor() {
    balances[msg.sender] = totalSupply_;
}

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

function balanceOf(address [msg.sender]) public override view returns (uint256) {
    return balances[msg.sender];
}

1 Answer 1

0

Your problem is balanceOf() function signature. In details, you cannot use msg.sender global keyword as parameter. To solve this problem you can try this:

function balanceOf(address _address) public override view returns (uint256) {
    return balances[_address];
}

I changed input parameter with an input data that when you'll call this function you will have to pass it. Another option is: don't have input parameter and use msg.sender directly into balances mapping in this way:

function balanceOf() public override view returns (uint256) {
    return balances[msg.sender];
}
2
  • Hello @Kerry99, that didn't solve the problem
    – Alfred H
    Apr 23 at 10:38
  • Can you include all your smart contract code?
    – Kerry99
    Apr 23 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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