Skip to content

Instantly share code, notes, and snippets.

@ashwinYardi
Created February 1, 2023 04:19
Show Gist options
  • Save ashwinYardi/ecfe79f9a6ccff896c45eef566924477 to your computer and use it in GitHub Desktop.
Save ashwinYardi/ecfe79f9a6ccff896c45eef566924477 to your computer and use it in GitHub Desktop.
Contract to demonstrate delegate call in solidity.
// 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