I am trying to execute a payable function from another contract. But for some reason that I don't understand, the sent value does not match, msg.value showing me the first require:
"msg.value and price do not match"
I have made two example contracts so that you can verify what I say.
Of course I enter the amount correctly, in fact, by logging I see the shipping figure and it is what is expected.
ContractReceiver:
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
contract ContractReceive {
uint256 public price = 0.1 ether;
uint8 public counter;
function buy(uint256 amount) public payable returns (bool) {
require(
msg.value == price,
"msg.value and price no match"
);
require(
msg.value == amount,
"msg.value and amount no match"
);
counter++;
return true;
}
}
ContractSender:
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
interface ContractReceive {
function buy(uint256 price) external payable returns (bool);
}
contract ContractSender {
ContractReceive contractReceive;
constructor(address _contractReceive){
contractReceive = ContractReceive(_contractReceive);
}
function buyfromContractSender() public payable {
contractReceive.buy(msg.value);
}
}