Edit
The original question below seems to work as expected. The issue happens with the call return data is empty. When the response
is nothing, the code below fails.
The following works, but is there a better way to do it?
bytes[] memory val;
for(uint i = 0; i < item.length; i++) {
(, bytes memory response) = addr.call.value(_value[i])(_data);
if (response.length != 0) {
val[i] = response;
}
}
I am unable to figure out how to store an array of bytes
. I understand that bytes
is an array of byte1
s, but I want to be able to store multiple bytes
in an array? So ideally, I would be able to define bytes[]
, where each member of that array is a new bytes
.
Some example code (which is not working) is:
bytes[] memory val;
for(uint i = 0; i < _value.length; i++) {
(, bytes memory response) = addr.call.value(_value[i])(_data);
val[i] = response;
}
This is reverting on val[i] = response;
. Does anyone know why?
val[i] = response
? The LHS and RHS are not even of the same type (let alone the fact that you're trying to set each entry in the output array to be equal to the input array)._value.length
, notitem.length
(what are these two variables anyway?).