I have a function which staticcalls a function which returns 3 different variables (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)
.
(bool success, bytes memory result) = contractAddr.staticcall(signatureID);
After the call, I would like to add the contractAddr
variable (which has an address type) to the result
byte array.
Based on the questions I found, I tried to use the following lines to add the address:
result[3] = abi.encodePacked(contractAddr);
And then got this error:
TypeError: Type bytes memory is not implicitly convertible to expected type bytes1.
I know this is because result
is memory
and it can't be altered. To fix this I tried to create a new bytes[]
but got the TypeError: Type bytes1 is not implicitly convertible to expected type bytes memory.
error when I tried the following:
(bool success, bytes memory result) = contractAddr.staticcall(signatureID);
bytes[] memory resultsCurrent = new bytes[](4);
resultsCurrent[0] = result[0];
resultsCurrent[1] = result[1];
resultsCurrent[2] = result[2];
resultsCurrent[3] = abi.encodePacked(contractAddr);
My question is, how could I create a bytes
type variable which holds the three object of result
at the index of 0,1,2
and abi.encodePacked(contractAddr)
at the index of 3
? My goal is to compose a view function from it to avoid paying gas fee for the calls.