0

I am trying to compile following on Remix IDE:

 pragma solidity ^0.5.1;
 contract testArray{
    address addr;
    function testA(uint _addr, uint[] emp) public{
       addr = _addr;
       for(uint i=0; i<emp.length; ++i){
          addr.send(emp[i].value);
      }
   }
}   

I am getting following error:

browser/arr.sol:4:31: TypeError: Data location must be "memory" for parameter in function, but none was given. function testA(uint _addr, uint[] emp) public{ ^--------^ Somebody please guide me.

1 Answer 1

1

In solidity 0.5.x you need to specify the memory location of parameters, and whether or not address variables are payable.

The below should work:

pragma solidity ^0.5.1;
contract testArray {
    address payable addr;
    function testA(address payable _addr, uint[] memory emp) public{
        addr = _addr;
        for(uint i=0; i<emp.length; ++i){
            addr.send(emp[i]);
        }
    }
}   
3
  • browser/arr.sol:7:13: Warning: Failure condition of 'send' ignored. Consider using 'transfer' instead. addr.send(emp[i]); ^---------------^ It gives me a warning. I tried transfer, it worked. Good. Leaving 'send' as it is should not be a problem for execution?
    – zak100
    Commented Jun 20, 2019 at 18:16
  • As per the error, if you're using send you should pay attention to its failure condition - it will return false rather than reverting like transfer does if the operation fails.
    – Adam Dossa
    Commented Jun 21, 2019 at 4:03
  • Is memory directive necessary only for array or even for simple variables i.e. non array variables
    – zak100
    Commented Jun 22, 2019 at 1:39

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.