0
contract Puzzle {
     address payable public owner ;
     bool public locked ;
     uint public reward ;
     bytes32 public diff ;
     bytes public solution ;


     /*constructor () payable public {*/
     constructor ( ) payable public{
     owner = msg.sender ;
     reward = msg.value ;
     locked = false ;
     /* Error:diff = bytes32 (11111); */ // pre - defined difficulty
     diff = bytes32 (uint256(11111));
  }

  function () payable external{ // main code , runs at every invocation
    if ( msg. sender == owner ){ // update reward
       //if ( locked )
       //throw ;
       require(!locked);
       bool val=owner.send ( reward );
       reward = msg.value ;
    }
    else
    if ( msg . data . length > 0){ // submit a solution
        require(!locked);
       //if ( locked ) throw ;
          if ( sha256 (msg. data ) < diff ){
             bool val=msg. sender . send ( reward ); // send reward
             solution = msg. data ;
             locked = true ;
       }}}}

I am getting following warning message:

solc puzzle_sha256.sol puzzle_sha256.sol:39:8: Warning: Unused local variable. bool val=owner.send ( reward ); ^------^ puzzle_sha256.sol:47:14: Warning: Unused local variable. bool val=msg. sender . send ( reward ); // send reward ^------^

Some body please guide me how to remove the warning. Also please check if I have used the require correctly or not.

Zulfi.

  • You can remove the warning by... using that variable. :-) – smarx Sep 16 at 4:11
1

bool val=owner.send ( reward );

Let's rewrite as

bool success = owner.send(reward);

Now, it says success is unused.

You can go:

bool success = owner.send(reward);
require(success, "The send failed.");

or

require(owner.send(reward), "The send failed.");

or

owner.transfer(reward); // reverts on fail

or, if this blog freaks you out (hat tip to Steve) https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/

then,

bool success;
bytes memory response;
(success, response) = msg.sender.call.value(reward)(""); // send reward
require(success, "The send failed.");

Hope it helps.

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.