Skip to content

Instantly share code, notes, and snippets.

@pom421
Created February 8, 2023 00:09
Show Gist options
  • Save pom421/f82ecde977dcbd7132470a63d472a47a to your computer and use it in GitHub Desktop.
Save pom421/f82ecde977dcbd7132470a63d472a47a to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
* @custom:dev-run-script ./scripts/deploy_with_ethers.ts
*/
contract Storage {
address currentOwner;
function setOwner(address _address) public {
currentOwner = _address;
}
function getBalance() public view returns (uint) {
return getBalanceForAddress(currentOwner);
}
function getBalanceForAddress(address _address) public view returns (uint) {
return _address.balance / 1 ether;
}
function transferTo(address payable _to) public payable {
_to.transfer(msg.value);
}
function transferEth(address payable _to) public payable returns (bool) {
(bool passed, ) = _to.call{ value: msg.value }("");
return passed;
}
function transferEtheWithCheck(uint _balance, address payable _to) public payable return (bool) {
require(getBalanceForAddress(currentOwner) > 1 wei, "Vous n'avez pas suffisamment d'eth");
transferEth(_to);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment