0

I started learning solidity, and I try to make a basic contract that add stocks to specific addresses. Here it is:


pragma solidity 0.8.8;

contract faya{
    
    holders[] public investors;
    
    mapping(address=>uint256)  public addressToStock;
    mapping(address=>bool)  public addressinvests;

    struct holders{
        address _address;
    }

   

 function deposit(address _address, uint256 _value) public {
    if (addressinvests(_address)==false){
        investors.push(holders(_address));
        addressToStock[_address]=_value;
                                        }


      if (addressinvests(_address)==true){
        addressToStock[_address]=addressToStock[_address]+_value;
                                        }
    
    
                                                            }

    function withdraw(address _address, uint256 _value) public {
        addressToStock[_address]=addressToStock[_address]-_value;
        investors[_address]-=_value;
    }}

When I compile in remix, I get the following error:

TypeError: Type is not callable --> faya coin.sol:20:9: | 20 | if (addressinvests(_address)==false){ | ^^^^^^^^^^^^^^^^^^^^^^^^

Any idea what this means and how to fix it?

1 Answer 1

1

It’s because addressinvests is a mapping, so your semantic for calling the value is incorrect.

Change addressinvests(_address) to addressinvests[_address]

…also, your naming convention for the mapping is odd considering status quo. I’d advise addressInvests

1
  • Thanks. It works now, and I will take your naming suggestion into my coding in the future.
    – FNH
    Apr 22, 2023 at 17:54

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.