Hello everyone, Why does the incorrect payment amount appear when I want to issue? Is there something wrong with me

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ZeroCouponBond {
address public issuer;
uint256 public faceValue;
uint256 public discountRate;
uint256 public maturity;
uint256 public issuePrice;
uint256 public issueBlock;
mapping(address => uint256) public balances;

constructor() {
    issuer = msg.sender;
    faceValue = 0.1 ether;
    discountRate = 20; 
    maturity = 10000; 
    issuePrice = faceValue * (100 - discountRate) / 100; 
}

function issue(address buyer) public payable {
    require(msg.value == issuePrice, "Incorrect payment amount");
    require(balances[buyer] == 0, "Bond already issued to this address");
    issueBlock = block.number;
    balances[buyer] = faceValue;
}

function redeem() public {
    require(block.number >= issueBlock + maturity, "Bond has not matured yet");
    require(balances[msg.sender] > 0, "No bond to redeem");
    payable(msg.sender).transfer(faceValue);
    balances[msg.sender] = 0;
}

}

    • List item
1 Like

The issue function contains this require statement:

require(msg.value == issuePrice, "Incorrect payment amount");

Which means msg.value should be greater than the issuePrice.
msg.value is the value of ether you send along with the function call. So you need to send that amount in the same transaction as the function call.

In this case, the issuePrice comes out to be 80000000000000000 wei as per the logic inside constructor. If you are using remix then just enter the value like this:

image

And then call the issue function.