Delegate calls in smart contract generally used to interact with other smart contract where Delegation is the one of the way. When a smart contract uses a delegate call to call a method, it executes and loads the method code from other smart contracts.
When a method executes by delegation call then the following values do not change
The smart contract that execute and loads the function of smart contract using delegate calls can write and read state variables and the smart contract that holds the methods is not subjected to writes or reads.
If Smart Contract A utilizes a deligate call to another Smart Contract B then the following statements will be true:
Smart Contract B functions can be read and write the variables of both Smart Contract A and B.
Smart Contract A has the following things:
Smart Contract B has the following things:
When we call the ‘init()’ method in Smart Contract A with 1 ETH:
1. These values will be set:
2. When‘init()’ method calls the ’setTName’ method in Smart Contract B then these values are returned:
3. In Smart Contract A, the value of the ‘tName’ state variable is changes.
In this article, we have learned how to delegate calls in a smart contract from Contract A to B and how state variables and functions work.