Last active
January 12, 2022 15:16
-
-
Save jtriley-eth/1a1d4bbf804448e8ad95ed27f5f14c8a to your computer and use it in GitHub Desktop.
Simple Solidity Contract Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
/// @title Simple read-write contract written in Solidity | |
/// @author jtriley.eth | |
/// @notice This is designed to be functionally identical to ./YulContract.sol | |
/// This is for educational purposes only, do not use in production. | |
contract SolidityContract { | |
/// @notice emitted when _myNumber is set | |
/// @param setter Indexed address of the number setter | |
/// @param oldNumber Last number stored | |
/// @param newNumber New number stored | |
event MyNumberSet( | |
address indexed setter, | |
uint256 oldNumber, | |
uint256 newNumber | |
); | |
/// @notice internal state variable | |
uint256 internal _myNumber; | |
/// @notice Reads _myNumber from state | |
/// @return _myNumber state variable | |
function read() public view returns (uint256) { | |
return _myNumber; | |
} | |
/// @notice Sets _myNumber, emits MyNumberSet | |
/// @param newNumber New number to be set | |
function set(uint256 newNumber) public { | |
uint256 oldNumber = _myNumber; | |
_myNumber = newNumber; | |
emit MyNumberSet(msg.sender, oldNumber, newNumber); | |
} | |
/// @notice Fallback, always returns 42 params not used | |
/// @return The number 42 encoded in bytes | |
fallback(bytes calldata) external returns (bytes memory) { | |
return abi.encode(42); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment