1

I need to extract a sub-bytes32 from a source bytes32 so I wrote this solidity function:

function bytesOf(bytes32 source, uint start, uint count) private pure returns(bytes32) {
    bytes32 result;
    uint end = start + count;
    for (uint i = start; i < end; i++) {
        result[i - start] = source[i];
    }
    return result;
}

Unfortunately that does not work and I get the error

TypeError: Expression has to be an lvalue.
    result[i - start] = source[i];
    ^---------------^

How would I do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.