Skip to content

Instantly share code, notes, and snippets.

@mudgen
Created September 24, 2021 13:06
Show Gist options
  • Select an option

  • Save mudgen/ba20bd0795a25f3750112d57d5fec9b9 to your computer and use it in GitHub Desktop.

Select an option

Save mudgen/ba20bd0795a25f3750112d57d5fec9b9 to your computer and use it in GitHub Desktop.
DiamondStorage storage ds = diamondStorage();
bytes4 functionSelector = bytes4(keccak256("myFunction(uint256)"));
// get facet address of function
address facet = ds.selectorToFacet[functionSelector];
bytes memory myFunctionCall = abi.encodeWithSelector(functionSelector, 4);
(bool success, uint result) = address(facet).delegatecall(myFunctionCall);
require(success, "myFunction failed");
@ersanyakit
Copy link

FACET_A

 function testData() public view returns (uint256 _responseData, string memory data) {
         _responseData = 100;
        data ="Hello Mudgen";
    }    

FACET_B

function getFacetData() external view returns(bool, uint256, string memory){
        LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
        bytes4 functionSelector =  bytes4(keccak256("testData()"));
        address facet = ds.selectorToFacetAndPosition[functionSelector].facetAddress;
        bytes memory myFunctionCall = abi.encodeWithSelector(functionSelector, 4);
        (bool success, bytes memory result) = address(facet).staticcall(myFunctionCall);
        (uint256 params, string memory data) = abi.decode(result, (uint256,string));
        return (false,params,data);
    }

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