Created
October 10, 2022 08:45
-
-
Save Un4G173N/45b401b42ac062e9572e6da1096a5b5c to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains 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.13; | |
// NOTE: Deploy this contract first | |
contract B { | |
// NOTE: storage layout must be the same as 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; | |
} | |
} | |
contract A { | |
uint public num; | |
address public sender; | |
uint public value; | |
function setVars(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) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment