赞
踩
- // SPDX-License-Identifier: GPL-3.0
-
- pragma solidity ^0.8.7;
-
- contract money_demo{
- address public admin;
- address payable public user;
- uint256 totalAmount;
-
- constructor(address _owner){
- admin = _owner; //决定一个值成为管理员
- }
-
- function deposit(uint256 _amount)public payable{ //充值函数
- if(_amount!=msg.value)return;
- user=payable(msg.sender); //记录是谁充值的
- totalAmount=_amount; //记录数值,表面记账
- //address(this).balance+= _amount;
-
-
- }
-
- function getBalance()public view returns(uint256,uint256){ //查看合约账户余额
-
- //this代表合约本身
- return (address(this).balance,totalAmount);
- }
-
- function withdraw(uint256 _amount)public payable{ //提现函数
- user.transfer(_amount); //这里的操作者并没有获得钱,而是将钱提现到了user账户
-
- }
- }
- // SPDX-License-Identifier: GPL-3.0
- pragma solidity >0.4.0;
- contract arrayTest2{
- function transfer() public payable{
- address account=0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
- payable(account).transfer(msg.value);
- }
- //在 Solidity 0.8之后,address就不是默认payable类型了。所以要在address前面加上payable的强制类型转换
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。