//存取主币
contract EtherWallet{
address payable public owner;
constructor(){
owner=payable(msg.sender);
}
receive() external payable{}
//提取
function withdraw(uint _amount) external{
//不是当前用户就报错
require(msg.sender==owner,"caller is not owner");
payable(msg.sender).transfer(_amount);
}
//获取余额
function getBalance() external view returns (uint){
return address(this).balance;
}
}
solidity基础(制作以太坊钱包合约)
最新推荐文章于 2024-11-11 23:12:22 发布
这是一个以太坊智能合约,名为EtherWallet,用于存储和提取以太币。合约设定有一个owner,只有合约创建者才能执行withdraw操作提取资金。合约包含安全检查,确保只有owner能转移资金,并提供方法查询余额。
1409

被折叠的 条评论
为什么被折叠?



