0

This is the function in solidity that calls the remote contract, and the same contract has a getter which is supposed to return the same string. I'm a bit new to solidity so I'm not exactly sure what's wrong here.

 function set(address contractAddress, string memory val) public {
        (bool success, ) = address(contractAddress).call(abi.encodeWithSignature("set(string)", val));
        require(success, "Failed");
      }
  • What you need is probably delegatecall() This video might be instructive https://www.youtube.com/watch?v=uawCDnxFJ-0 – Sky Feb 22 '22 at 17:08
  • @Sky thanks for the link, watched it but I can't figure out how it helps in this case. The output changed, but still wasn't the expected output. I don't have access to the remote contract itself, just the bytecode for the transaction data. – licorice Feb 22 '22 at 17:29
  • Ok, but you know the address of the remote contract and you want to call a function inside of it? Right? – Sky Feb 22 '22 at 18:46
  • @Sky yes. I don't seem to have a problem calling the function, the success return is true. But the remote contract also has a getter which is supposed to return the same value i set. – licorice Feb 22 '22 at 19:06
  • What is the name of the function you are calling inside of the remote contracts. Because as far as I can see, you are calling set() function that receives a string. – Sky Feb 22 '22 at 19:09
  • @Sky this contract is actually executed through a test. First it does sendTransaction() with bytecode as data, then using the address of the remote contract which is passed into this contract's function it sets a value, then calls a get() function of the remote contract with the same address. And it's supposed to return the same string that was passed into set(), but the problem is specified to be in the set() i posted. – licorice Feb 22 '22 at 19:32
  • FYI, https://forum.openzeppelin.com/t/delegatecall-for-an-already-deployed-smart-contract-only-have-bytecode-and-need-to-store-a-value-its-storage/24450/1 is the exact problem with all the code. Guess we are working on the same problem xD – licorice Feb 22 '22 at 20:42
  • @Sky delegatecall won't work here, the semantic is completely different https://ethereum.stackexchange.com/questions/3667/difference-between-call-callcode-and-delegatecall. – Ismael Feb 22 '22 at 21:53
  • @licorice You can call the getter similarly to how the setter is called. Then you can to decode the second value returned by the call like here https://ethereum.stackexchange.com/questions/115567/decoding-return-bytes-from-solidity-address-call. – Ismael Feb 22 '22 at 21:56

0 Answers0