Skip to content

Instantly share code, notes, and snippets.

@daniellehrner
Last active April 5, 2019 15:04
Show Gist options
  • Save daniellehrner/c7f809eb62201592cdba458991a4f2e3 to your computer and use it in GitHub Desktop.
Save daniellehrner/c7f809eb62201592cdba458991a4f2e3 to your computer and use it in GitHub Desktop.
Wrapper function to store a balance in eternal storage
function setBalance(address _who, uint256 _value) external {
setUInt256(
// computes the Ethereum-SHA-3 (Keccak-256) hash
keccak256(
// performs packed encoding of the given arguments,
// as the hash function only accepts one argument
abi.encodePacked(
// we use a hardcoded string to create a different
// hash for the same dynamic value
"balance",
// a unique dynamic value is needed to clearly
// assign the value to an account
_who
)
),
// the value we want to store
_value
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment