Solidity: .call() vs. .delegatecall() vs. Libraries

In this short video we look at the difference between .call() vs. .delegatecall() vs. Libraries in Solidity.

Specifically we look at a very simple contract that emits an event with the address of the global variable this.

This has caused some confusion in the past and I hope this short example will clear up things a bit.

Here is the Video:

Link to YouTube

Here is the contract, if you would like to try it in Remix:

pragma solidity ^0.4.17;

contract SomeContract {
    event callMeMaybeEvent(address _from);
    function callMeMaybe() payable public {
        callMeMaybeEvent(this);
    }
}

contract ThatCallsSomeContract {
    function callTheOtherContract(address _contractAddress) public {
        require(_contractAddress.call(bytes4(keccak256("callMeMaybe()"))));
        require(_contractAddress.delegatecall(bytes4(keccak256("callMeMaybe()"))));
        SomeLib.calledSomeLibFun();
    }
}

library SomeLib {
    event calledSomeLib(address _from);
    function calledSomeLibFun() public {
        calledSomeLib(this);
    }
}

Join the most thorough course on Ethereum Development out there! The Ethereum Developer Masterclass where you will learn everything there is to know about Blockchain and Solidity Development.