2

I am a beginner to solidity and I came across this concept called "Low-Level Calls". What exactly is a Low-level function? and How is it different from others?

3

So in solidity the address object has this method call through which you can call every function you want and if the address implements it will be triggered.
For example:

contract SomeContract {
    function any() public {
        (bool success, bytes memory result) = addr.call(abi.encodeWithSignature("myFunction(uint,address)", 10, msg.sender);
        // if success is `true` the function exists and it had returned some result
        (uint a, uint b) = abi.decode(result, (uint, uint)); // This is an example of how the result might have been decoded
    }
}

You can also use this syntax:

address.call.gas(50000).value(1 ether)(data);

Here you forward some ethe and gas. the variable data is something like this:

0x38ed1739000000000000000000000000000000000000000000000000127126c0ab345650000000000000000000000000000000000000000000000000000000012a8ef05e00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000e1751fb76a2f4a8288c0af347def0d5fd5313a7000000000000000000000000000000000000000000000000000000006168497f00000000000000000000000000000000000000000000000000000000000000020000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f6190000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174

The first 4bites after the 0x symbol represent the function signature - the first for bytes of the function signature after encoding it with the keccak256 hash function, in this case it is abi.keccak256("swapExactTokensForTokens(uint256,uint256,address[],address,uint256)") and from the result you are using the first 4 bytes. Everything after this 4bits is representation of the calldata which will be parsed to the functions arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.