Created
August 30, 2020 12:33
-
-
Save ilovelili/3b9d1168978c1dc0595007f685acd133 to your computer and use it in GitHub Desktop.
solidity storage vs memory
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: ISC | |
pragma solidity ^0.7.0; | |
contract Storage { | |
struct Test { | |
uint256 id; | |
uint256 count; | |
} | |
uint256 public storageId; | |
mapping(uint256 => Test) public tests; | |
function createStorage() external { | |
storageId++; | |
tests[storageId] = Test(storageId, 0); | |
} | |
function testStorage(uint256 _storageId) external { | |
// should be storage to change the tests status | |
Test storage t = tests[_storageId]; | |
t.count = 100; | |
} | |
/*function testStorage(uint256 _storageId) view external { | |
Test memory t = tests[_storageId]; | |
t.count = 100; | |
}*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment