Created
November 24, 2021 21:27
-
-
Save PatrickAlphaC/211e1bb0548c80944ee57be6d6a28c3f to your computer and use it in GitHub Desktop.
How to quickly encode and decode things. For more, check here: https://docs.soliditylang.org/en/v0.8.10/units-and-global-variables.html?highlight=abi.encode#abi-encoding-and-decoding-functions
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
// This example code is designed to quickly deploy an example contract using Remix. | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
contract EncodingFun { | |
function encodeThenDecode(uint256 value) public pure returns (uint256) { | |
bytes memory encodedData = abi.encodePacked(value); | |
uint256 decodedData = abi.decode(encodedData, (uint256)); | |
return decodedData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment