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

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

15 人参与  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