当前位置:首页 » 《随便一记》 » 正文

solidity 0.8.0 以上版本:冲提ht、bnb_chen

9 人参与  2021年11月16日 08:23  分类 : 《随便一记》  评论

点击全文阅读


 // SPDX-License-Identifier: MIT
 pragma solidity ^0.8.3;
 
 contract ContractBalanceTest {
     address public owner;
 
     constructor() public payable {
         owner = msg.sender;
     }
 
     modifier onlyOwner () {
       require(msg.sender == owner, "This can only be called by the contract owner!");
       _;
     }
 
     function deposit() payable public {
     }
 
     function depositAmount(uint256 amount) payable public {
         require(msg.value == amount);
     }
 
     function withdraw() payable onlyOwner public {
         payable(msg.sender).transfer(address(this).balance);
     }
 
     function withdrawAmount(uint256 amount) onlyOwner payable public {
         require(msg.value == amount);
         require(amount <= getBalance());
         payable(msg.sender).transfer(amount); //this not work
         //msg.sender.transfer(getBalance()); // this ok
     }
 
     function getBalance() public view returns (uint256) {
         return address(this).balance;
     }
 }

 

 // SPDX-License-Identifier: MIT
 pragma solidity ^0.8.3;
 
 contract ContractBalanceTest {
     address public owner;
 
     constructor() public payable {
         owner = msg.sender;
     }
 
     modifier onlyOwner () {
       require(msg.sender == owner, "This can only be called by the contract owner!");
       _;
     }
 
     function deposit() payable public {
     }
 
     function depositAmount(uint256 amount) payable public {
         require(msg.value == amount);
     }
 
     function withdraw(uint256 amount)  onlyOwner public {
         //payable(msg.sender).transfer(address(this).balance);
         (bool success, ) = msg.sender.call{value: amount}(new bytes(0));
     }
 
     function withdrawAmount(uint256 amount) payable public {
         //require(msg.value == amount);
         require(amount <= getBalance());
         //payable(msg.sender).transfer(amount); //this not work
        (bool success, ) = msg.sender.call{value: amount}(new bytes(0));
         //msg.sender.transfer(getBalance()); // this ok
     }
 
     function getBalance() public view returns (uint256) {
         return address(this).balance;
     }
 }


点击全文阅读


本文链接:http://zhangshiyu.com/post/30917.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • 被豪门新郎打断肋骨后,豪门慌了全文免费在线阅读_[周贺顾秉天顾明珠]章节彩蛋限时释出‌
  • [斤斤计较的老婆]节选隐藏剧情入口‌_林倩朋友美其名曰无弹窗阅读
  • 你揽星辰我拥黄昏+后续+结局(尤雾眠晏沉舟)列表_你揽星辰我拥黄昏+后续+结局
  • 听说你爱我独家章节限时试读_江时闻小雨朋友限时免费***章节速览
  • 完结文爱如蜉蝣,朝生暮死列表_完结文爱如蜉蝣,朝生暮死(沈栀晏淮)
  • 爱如蜉蝣,朝生暮死沈栀晏淮结局+番外(沈栀晏淮)全书免费_(沈栀晏淮免费爱如蜉蝣,朝生暮死沈栀晏淮结局+番外读全书)列表_笔趣阁爱如蜉蝣,朝生暮死沈栀晏淮结局+番外
  • 爱意随风搁浅完结版免费阅读_陆竞野绵绵宝宝口碑神作必读篇章
  • 爱乃因果(孟夏瑜)_爱乃因果列表_笔趣阁(爱乃因果)
  • 给你的第三封信是遗言全书+后续+结局(沈佳芮顾温言)列表_给你的第三封信是遗言(沈佳芮顾温言)给你的第三封信是遗言全书+后续+结局在线
  • (番外)+(全书)苔藓爬满旧日诺言全书+后续***_(顾砚廷慕晚夏)苔藓爬满旧日诺言全书+后续列表_笔趣阁(顾砚廷慕晚夏)
  • 花落花开终别离结局+番外(祁欢江临州)全祁欢江临州文结局_祁欢江临州+结局列表_笔趣阁(花落花开终别离结局+番外)
  • 抓阄选妻角色专属支线试读入口_珊珊刘思语周承小说节选试读

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1