Created
June 2, 2021 14:25
-
-
Save PatrickAlphaC/73e40fc7ffa0203dbd892a6bde53df34 to your computer and use it in GitHub Desktop.
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.0; | |
contract A { | |
uint public num; | |
address public sender; | |
uint public value; | |
function setVars(uint _num) public payable { | |
num = _num; | |
sender = msg.sender; | |
value = msg.value; | |
} | |
function setVarsDelegated(address _contract, uint _num) public payable { | |
// A's storage is set, B is not modified. | |
(bool success, bytes memory data) = _contract.delegatecall( | |
abi.encodeWithSignature("setVars(uint256)", _num) | |
); | |
} | |
function setVarsCalled(address _contract, uint _num) public payable { | |
// A's storage is set, B is not modified. | |
(bool success, bytes memory data) = _contract.call( | |
abi.encodeWithSignature("setVars(uint256)", _num) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment