LEARN SOLIDITY LESSON
Keccak256 Solidity. Typecasting Solidity. Events Solidity
Keccak256 Solidity
Ethereum has the hash function keccak256 built in, which is a version of SHA3. A hash function basically maps an input into a random 256-bit hexadecimal number. A slight change in the input will cause a large change in the hash.
//6e91ec6b618bb462a4a6ee5aa2cb0e9cf30f7a052bb467b0ba58b8748c00d2e5 keccak256(abi.encodePacked("aaaab")); //b1f078126895a1424524de5321b339ab00408010b7cf0e6ed451514981e58aa9 keccak256(abi.encodePacked("aaaac"));
Typecasting Solidity
Sometimes you need to convert between data types. Take the following example:
int8 a = 5; uint b = 6; uint8 c = a * uint8(b);
Events Solidity
Events are a way for your contract to communicate that something happened on the blockchain to your app front-end, which can be 'listening' for certain events and take action when they happen.
//SOLIDITY
event IntegersAdded(uint x, uint y, uint result); function add(uint _x, uint _y) public returns (uint) { uint result = _x + _y; // run emit IntegersAdded(_x, _y, result); return result; }
//JAVASCRIPT
YourContract.IntegersAdded(function(error, result) { // do something with result })
Comments