Created
December 5, 2022 07:18
-
-
Save casweeney/6fb56293ccf8e5afa39bd163b3e027f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
| contract TypeCasting { | |
| event Converted(address owner, string message); | |
| bytes32 public x = "This is the beginning of Adddddd"; | |
| bytes32 public value = "100"; | |
| string public y = "This is the beginning of Adddddd"; | |
| address public owner; | |
| constructor() { | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner() { | |
| require(msg.sender == owner, "Not only"); | |
| _; | |
| } | |
| function changeOwner(address _address) public onlyOwner { | |
| owner = _address; | |
| emit Converted(_address, "Ownership transfered"); | |
| } | |
| function showOwner() external view returns (address) { | |
| return owner; | |
| } | |
| function convertByteToString() public view returns(string memory) { | |
| string memory result = string(abi.encodePacked(x)); | |
| return result; | |
| } | |
| function convertExternalByteToString(bytes32 _data) public pure returns(string memory) { | |
| string memory result = string(abi.encodePacked(bytes32(_data))); | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment