Solidity version 8 error: comparing uint with msg.value

Hi,
I am getting compilation error with following Smart contract written in version 8Solidity:

//SPDX-License-Identifier: UNLICENSED 
pragma solidity ^0.8.10; 
contract T { 
   address payable k; 
   uint public cP = 100; 
   address payable owner; 
   constructor() { 
      owner =  payable (msg.sender); 
   } 
   function sC(uint val) public payable{ 
      owner.transfer(val); 
   } 
   receive() external payable { 
      if (msg.value < cP) revert; 
      int c= 100; 
      k.send(c); 
   } 
}

I am getting the following error:

TypeError: No matching declaration found after variable lookup. 
--> remix2.sol:17:22: 
| 
17 | if (msg.value < cP) revert; 
| ^^^^^^

Somebody please guide me.
Zulfi.

1 Like

Hi @zak100

Here is a working code:

//SPDX-License-Identifier: UNLICENSED 
pragma solidity ^0.8.10; 
contract T { 
   address payable k; 
   uint public cP = 100; 
   address payable owner; 
   constructor(address payable _k) { 
      owner =  payable (msg.sender);
      k = _k;
   }
   function sC(uint val) public payable{ 
      owner.transfer(val); 
   } 
   receive() external payable { 
      if (msg.value < cP) revert("msg.value is too low"); 
      uint256 c = 100; 
      k.transfer(c); 
   } 
}
  1. You had a typo revert instead of revert().
  2. Also you need to declare the k address, I added it to the constructor
  3. You can transfer only uint256 values.
  4. use transfer() instead of send() if you don’t return boolean like this:
bool isSent = k.send(c); 
require(isSent , "Failed to send");
1 Like