12

I'm attempting to use the function send() in Solidity I've got this error when i try to compile my contract with truffle :

Warning: Return value of low-level calls not used.

any idea about it?

thank you

Shane Fontaine
  • 18,036
  • 20
  • 54
  • 82

3 Answers3

8

It is because your code is not checking the return status from the send(...) function:

Using this code below in Solidity Online:

pragma solidity ^0.4.0;

contract Test {
    function testit(address a) {
        a.send(123);
    }
}

I get the the following warning message: Warning: Return value of low-level calls not used..

Using the code below instead will remove the warning:

pragma solidity ^0.4.0;

contract Test {
    function testit(address a) {
        if (!a.send(123))
            throw;
    }
}

The compiler is warning you to check the return status of the send(...) function. Solution - check the return status. This is one of the recommendations on smart contract best practices after the USD 50 million The DAO hack.

Further reference - Ethereum Contract Security Techniques and Tips.

BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193
6

you could use a modifier :

modifier send_it(uint _amount, address _address ) {
    if (msg.value < _amount)
        throw;
    _
    if (msg.value > _amount)
        _address .send(_amount - msg.value);
}

function x(address _newOwner) send_it(200 ether,msg.sender) //exemple {

 }

or you could just use simple checking (throw if send failed for some reason):

if (_address.send())
 throw;

Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75
2

In solidity version 0.5.0 they have made breaking changes and returns bool and bytes. Reference is here.

So you have to use:

(bool success, bytes memory data) = otherContract.send("f")

to get the return values and then use it accordingly.