1

Assume calldata for my smart contract being address as bytes, and few amounts as bytes chained together.

How can I extract the bytes for address and store it in

address memory address_ =

and the amounts dynamically in

uint256 memory amount_1 =

uint256 memory amount_2 =

uint256 memory amount_3 =

I'd ideally want to convert straight to uint memory and address memory instead of just splitting them as bytes and working with bytes in the contract logic.

  • How do I split that at all to get the correct array lengths?
  • How can I make my contract know at what index to split the bytes? Let's say there's only 2 amounts... I could pass the index for splitting it, but is that good practice? Maybe a separator byte?

I've found 2 methods on ethereum.stackexchange, but I don't think they would be complete without a method to split dynamically...

(1)

    bytes4 selector;
    assembly {
        selector := calldataload(data.offset)
    }

(2)

address(uint160(bytes20(keccak256(abi.encodePacked(...)))))

and I require a bit of further explanations about those methods. If you do understand them, I'll be grateful for a contribution/explanation. Thanks!

0

Your Answer

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

Browse other questions tagged or ask your own question.