A hash function is which takes arbitrary size input and gives fixed size output.
Properties:
- Deterministic
- quick
- irreversible
- collision resistant
one way to pass byte to keccak256 is via abi.encodPacked.It takes all type of data and any amount of input
abi.encodePacked(_text,_num,_addr);
How to sign and Verify the messages?
- Create a message to sign
- Hash the Message
- Sign the hash (offchain, keep your private key secret)
- Recreate hash from the original message
- Recover signer from signature and Hash
- compare recovered signer to claimed signer
contract can send and receive ether by using payable
- Depositing ether
- withdrawing ether
- Transferring ether
The given function still returns false in case an error occurs, that is why keep the usage of require() in mind. Its principal difference from the two previous functions is an opportunity to set gas limit via .gas(gasLimit) modifier. It is necessary in case the payable function of the contract receiving ether performs a complex logic, that requires plenty of gas.
address.call{value: x}()
addr.call{value: msg.value, gas: 5000}(
abi.encodeWithSignature("foo(string,uint256)", "call foo", 123)
Notes:
- No space should bebetween the parameters.
- Fallback function does not return anything
(bool success, bytes memory data) = _addr.call(
abi.encodeWithSignature("doesNotExist()"));
emit Response(success, data);
output: "args": { "0": true, "1": "0x", "success": true, "data": "0x" }
- Normal function calls Data is what is returned from foo function
Output: "args": { "0": true, "1": "0x000000000000000000000000000000000000000000000000000000000000007c", "success": true, "data": "0x000000000000000000000000000000000000000000000000000000000000007c" } }
-
Low level fun similar to call method
-
When contract A delegatecall contract B it runs B's code inside A's context(storage, msg.sender, msg.value)
-
can upgrade contract A without changing any code inside it.
- Help in writing upgradable contract
Notes:
- The order of the state variable in contract B should be in same order as contract A.