Skip to content

Instantly share code, notes, and snippets.

@ilovelili
Created August 30, 2020 12:33
Show Gist options
  • Save ilovelili/3b9d1168978c1dc0595007f685acd133 to your computer and use it in GitHub Desktop.
Save ilovelili/3b9d1168978c1dc0595007f685acd133 to your computer and use it in GitHub Desktop.
solidity storage vs memory
// 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