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

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

6 人参与  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://m.zhangshiyu.com/post/30917.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

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

最新文章

  • [被丢下忘川后,阎王夫君悔疯了]免费试读_秦温云裳阎王情感冲突精选段落
  • 你是我难愈的旧伤结局+番外(傅深铭夏晚星)列表_你是我难愈的旧伤结局+番外(傅深铭夏晚星)结局篇+番外在线
  • 九幽不渡卿全书+后续+结局(孟卿卿谢昭远绮萝)_(孟卿卿谢昭远绮萝)九幽不渡卿全书+后续+结局列表_笔趣阁(孟卿卿谢昭远绮萝)
  • [替老婆驻外十年,她和好兄弟成双入对]情感冲突精选段落_许科魏琳琳萌萌节选试读
  • 许我三千繁星愿全书+后续+结局(楚砚风慕星眠苏向阳)结局_(楚砚风慕星眠苏向阳许我三千繁星愿全书+后续+结局全书结局)结局列表_笔趣阁(楚砚风慕星眠苏向阳)
  • 你是我未拆的遗书裴谨言桑年+后续(桑年裴谨言)_(桑年裴谨言)你是我未拆的遗书裴谨言桑年+后续列表_笔趣阁(桑年裴谨言)
  • 弦歌断处雪满头最新后续章节在线阅读_江姝恋季容生白彦爆款小说高能章节试读
  • 男友青梅砍我手后,又让我做婚礼蛋糕免费试读_[蕊蕊林子青梅]小说章节免费试读
  • 楚砚风慕星眠(许我三千繁星愿结局+番外)_楚砚风慕星眠列表_笔趣阁(许我三千繁星愿结局+番外)
  • 也曾偷藏欢喜结局+番外乔喜商凛全书免费乔喜商凛_(也曾偷藏欢喜结局+番外乔喜商凛)乔喜商凛列表笔趣阁(也曾偷藏欢喜结局+番外乔喜商凛)
  • [重生八零:我果断退婚嫁京圈大佬]多结局分支任选读_林年年陆辰凡最新章节在线阅读
  • 长叹雁归难留全书+后续(傅迟宴林溪)全书傅迟宴林溪读结局_傅迟宴林溪读结局列表_笔趣阁(长叹雁归难留全书+后续)

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

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