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.

1 Answer 1


The problem here is, the returned result from staticcall is not of a type bytes array, but bytes. So your function will not work as intended anyhow. Depending on what you want to achieve you have a few options.

  1. Encode address with result, where rez is of type bytes: rez = abi.encodePacked(result, contractAddr);

  2. Create bytes array and pass result as first element and address as second

bytes[] memory resultsCurrent= new bytes[](2); 
resultsCurrent[0] = result; 
resultsCurrent[1] = abi.encodePacked(contractAddr);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.