Skip to content

Instantly share code, notes, and snippets.

@mudgen
Created July 23, 2021 04:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mudgen/ff047377041ed9d4975bad5c50749f83 to your computer and use it in GitHub Desktop.
Save mudgen/ff047377041ed9d4975bad5c50749f83 to your computer and use it in GitHub Desktop.
// 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;
}
}
@moeid3
Copy link

moeid3 commented Dec 13, 2023

So satisfiying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment