Created
July 23, 2021 04:32
-
-
Save mudgen/ff047377041ed9d4975bad5c50749f83 to your computer and use it in GitHub Desktop.
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.6; | |
contract ContractA { | |
string internal tokenName = "FunToken"; | |
function initialize() external { | |
address contractBAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F; | |
(bool success, bytes memory returndata) = contractBAddress.delegatecall( | |
abi.encodeWithSelector(ContractB.setTokenName.selector, "BoringToken") | |
); | |
// if the function call reverted | |
if (success == false) { | |
// if there is a return reason string | |
if (returndata.length > 0) { | |
// bubble up any reason for revert | |
assembly { | |
let returndata_size := mload(returndata) | |
revert(add(32, returndata), returndata_size) | |
} | |
} else { | |
revert("Function call reverted"); | |
} | |
} | |
} | |
} | |
contract ContractB { | |
string internal tokenName = "BoringToken"; | |
function setTokenName(string calldata _newName) external { | |
tokenName = _newName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So satisfiying