38: DelegateCall
DelegateCall is a Solidity feature which allows a function to be called on another contract while preserving the caller's address and associated code. This article will discuss DelegateCall by some examples.
Example 1
Let's assume we have two contracts:
Contract A
Contract B
Contract A calls the function doSomething in Contract B using delegatecall.
By using delegatecall, the function doSomething in Contract B will be called while preserving the caller's address and associated code. In this example, the address of Contract A will be preserved in the call to Contract B.
Example 2
Let's assume we have three contracts:
Contract A
Contract B
Contract C
Contract A calls the function doSomething in Contract B using delegatecall. Furthermore, Contract B calls the function doSomethingElse in Contract C using delegatecall.
By using delegatecall, the function doSomething in Contract B will be called while preserving the caller's address and associated code. Furthermore, the function doSomethingElse in Contract C will be called while preserving the address of Contract B and its associated code. Thus, in this example, the address of Contract A will be preserved in the call to Contract C.
That's it for the lesson 38! In the next lesson, Calling Other Contract
Last updated