0

I am getting a syntax error. I am not sure if its a problem related to 2D mapping or 2D array. My code is given below:

contract Stealing{
   
   mapping (address => uint) balances;
   mapping (address => bool) frozenAccount;
   mapping (address => uint) allowed;
   function transferFrom ( address from , address to , uint value )public returns ( bool success ) {
      // checking account is freeze or not
      if( frozenAccount [ msg. sender ]) return false ;
         // checking the from should have enough coins
      if( balances [ from ] < value ) return false ;
         // checking for allowance
      if( allowed [ from ][ msg. sender ] >= value ) return false ;
         // checking for overflows
      if( balances [to] + value < balances [to ]) return false ;
      balances [ from ] -= value ;
      allowed [ from ][ msg . sender ] -= value ;
      balances [to] += value ; // Notify anyone listening that this transfer took place
      transferFrom (from , to , value );
    return true ;
 }
}

The error message is:

prg9.sol:37:11: Error: Indexed expression has to be a type, mapping or array (is uint256) if( allowed [ from ][ msg. sender ] >= value ) return false ;

Somebody please guide me. Zulfi.

1 Answer 1

1

You haven't declared allowed as a 2D mapping, but you're trying to use it as one.

You need: mapping (address => mapping (address => uint256)) private allowed;

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.