Created
August 26, 2021 11:28
-
-
Save andrejrakic/3f972eba41d28a5839d2de80120bf95d to your computer and use it in GitHub Desktop.
Simple smart contract to swap two variables in Solidity
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: UNLICENSED | |
pragma solidity ^0.8.0; | |
// Simple contract to swap two variables in Solidity | |
contract Swapper { | |
uint8 public x = 1; | |
uint8 public y = 2; | |
function swap() public { | |
/** | |
* Old school way | |
* | |
* uint8 temp = x; | |
* x = y; | |
* y = temp; | |
*/ | |
// more cool way 😎 | |
(x, y) = (y, x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment