需要味觉。取决于不同的情况

发布于 2025-02-07 20:11:01 字数 420 浏览 2 评论 0原文

我的情况是,我拥有免费的薄荷功能,就像发件人有3个项目免费薄荷,并尝试铸造5个项目,我想要求发件人只需支付2个项目。

它不起作用,我认为错误在这里:

int256 payableMints = int256(_mintAmount - freeMints);

   if(payableMints < 0){
       payableMints = 0;
   }
   
   if(payableMints > 0){
       require(msg.value >= (cost * uint256(payableMints)));
   }
   else{
       require(msg.value >= (freeMintCost * _mintAmount));
   }

我做错了什么吗?

My case is I have item free mint functionality like if sender have 3 item free mint and trying to mint 5 item i want to ask sender to pay only for 2 items.

it doesnot works and I think error is here:

int256 payableMints = int256(_mintAmount - freeMints);

   if(payableMints < 0){
       payableMints = 0;
   }
   
   if(payableMints > 0){
       require(msg.value >= (cost * uint256(payableMints)));
   }
   else{
       require(msg.value >= (freeMintCost * _mintAmount));
   }

am i doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九厘米的零° 2025-02-14 20:11:01

我不知道什么是freemintCost的类型,但是如果它是uint256类型,例如,您需要将_mintamount转换为uint256:

 require(msg.value >= (freeMintCost * uint256(_mintAmount)));

i i测试了此代码并有效:

contract Test {

   int256 freeMints = 3;
   uint256 cost = 1000;
   uint256 freeMintCost = 0;
    
   function mint(int256 _mintAmount) public payable {
       int256 payableMints = int256(_mintAmount - freeMints);
       if(payableMints < 0){
        payableMints = 0;
       }
       if(payableMints > 0){
        require(msg.value >= (cost * uint256(payableMints)));
       }
       else{
        require(msg.value >= (freeMintCost * uint256(_mintAmount)));
       }
   }
}

I dont know what is the type of freeMintCost but if it is a uint256 type, for example, you need to convert _mintAmount to uint256:

 require(msg.value >= (freeMintCost * uint256(_mintAmount)));

I tested this code and worked:

contract Test {

   int256 freeMints = 3;
   uint256 cost = 1000;
   uint256 freeMintCost = 0;
    
   function mint(int256 _mintAmount) public payable {
       int256 payableMints = int256(_mintAmount - freeMints);
       if(payableMints < 0){
        payableMints = 0;
       }
       if(payableMints > 0){
        require(msg.value >= (cost * uint256(payableMints)));
       }
       else{
        require(msg.value >= (freeMintCost * uint256(_mintAmount)));
       }
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文