Hi I have a function that returns a uint256.

    function getLatestPrice() public view returns (int) {
        /*uint80 roundID*/,
        int price,
        /*uint startedAt*/,
        /*uint timeStamp*/,
        /*uint80 answeredInRound*/
    ) = priceFeed.latestRoundData();
    return price;

I want to compare this amount to msg.value, but the editor says >= is not compatible with uint/int256?

    require(msg.value >= getLatestPrice(), "insufficient number");

TypeError: Operator >= not compatible with types uint256 and int256

How can I require msg.value to be greater than or equal to my uint256?

Thank you,

1 Answer 1


You need to cast the type, given that this is a price from a pricefeed you can do that without worrying but be mindful in future contracts. The following should work:

require(msg.value >= uint256(getLatestPrice()), "insufficient number");
  • 1
    You saved my life. Thank you. Commented Jun 4, 2022 at 6:34

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.