Created
February 1, 2023 04:19
-
-
Save ashwinYardi/ecfe79f9a6ccff896c45eef566924477 to your computer and use it in GitHub Desktop.
Contract to demonstrate delegate call in solidity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
// NOTE: Deploy this contract first | |
contract IronMan { | |
uint public power; | |
uint public speed; | |
uint public impact; | |
function increasePower(uint _scale) public payable { | |
num = num + ( num * _scale ); | |
speed = speed + ( speed * _scale ); | |
impact = impact + ( impact * _scale ); | |
} | |
} | |
contract CaptainAmerica { | |
uint public power; | |
address public speed; | |
uint public impact; | |
function askIronManForHelp(address _ironMan) public payable { | |
// Iron Man scales up Captain America's power. | |
(bool success, bytes memory data) = _ironMan.delegatecall( | |
abi.encodeWithSignature("increasePower(uint256)", 10) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment