Skip to content

Instantly share code, notes, and snippets.

@casweeney
Created December 5, 2022 07:18
Show Gist options
  • Select an option

  • Save casweeney/6fb56293ccf8e5afa39bd163b3e027f3 to your computer and use it in GitHub Desktop.

Select an option

Save casweeney/6fb56293ccf8e5afa39bd163b3e027f3 to your computer and use it in GitHub Desktop.
// 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