Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Created June 2, 2021 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickAlphaC/73e40fc7ffa0203dbd892a6bde53df34 to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/73e40fc7ffa0203dbd892a6bde53df34 to your computer and use it in GitHub Desktop.
// 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