Skip to content

Instantly share code, notes, and snippets.

@0xAnon101
Last active January 26, 2021 11:03
Show Gist options
  • Select an option

  • Save 0xAnon101/d56d2913f2d5b253c10f7e22c1b15da7 to your computer and use it in GitHub Desktop.

Select an option

Save 0xAnon101/d56d2913f2d5b253c10f7e22c1b15da7 to your computer and use it in GitHub Desktop.
Address coercion
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.7.0;
contract Address {
// address addressA = 0x111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFFCCCC; notimplicity convertible
address addressA;
function compressAddressSize() external pure returns(address ) {
// explicit coercion
bytes32 constantValue = 0x111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFFCCCC;
address resultantAddress = address(uint160(uint256(constantValue)));
// 20 byte address
return resultantAddress;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.7.0;
contract Address {
event OwnerChanged( address indexed oldOwner, address indexed newOwner);
address public owner;
uint256 public etherValue;
mapping(address => uint256) public balances;
constructor() public {
owner = msg.sender;
balances[owner] = 0;
emit OwnerChanged(address(0), owner);
}
modifier isOwner() {
require(msg.sender == owner, "The user is not owner");
_;
}
function changeOwner(address _newOwner) public isOwner {
owner = _newOwner;
emit OwnerChanged(owner, _newOwner);
}
function send() external payable returns(bool) {
balances[msg.sender] = msg.value;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment