uniswap creates paths in the following way:

ISwapRouter.ExactOutputParams memory params =
        path: abi.encodePacked(WETH9, poolFee, USDC, poolFee, DAI),
        recipient: msg.sender,
        deadline: block.timestamp,
        amountOut: amountOut,
        amountInMaximum: amountInMaximum

I have a function accepting packed data as bytes, how do I read the data back out I've tried the following but It doesn't work with packed data

(address inputToken, uint24 fee, address outputToken)  = abi.decode(swapResolverOptions.path, (address, uint24, address));

2 Answers 2


Unfortunately, there's no tool to do that at the moment. This is what the documentation says: Since the encoding is ambiguous, there is no decoding function..

Check the docs here: https://docs.soliditylang.org/en/v0.8.11/abi-spec.html#non-standard-packed-mode

I have answered a similar question before, take a look to get an idea on how to try to decode this data if you know exactly the types: Decoding several variables from a slot in contract


Note: this is only for decoding path, and is not a general solution if you want a more general solution you can parse out the length of your data type by the offset using this bytes lib

This can be decoded using uniswaps Path library

import '@uniswap/v3-periphery/contracts/libraries/Path.sol';

then declare using for bytes:

using Path for bytes;

Then you can decode using the library methods:

(address tokenIn, address tokenOut, uint24 fee) = swapResolverOptions.path.decodeFirstPool();
  • 1
    Maybe worth adding this is working for this very precise use-case and is by no mean a general solution to decode abi.encodePacked data, as OP's title mention Commented Jan 6, 2023 at 22:02
  • 1
    @DrGorilla.eth I've updated it
    – Ritzy Dev
    Commented Jan 6, 2023 at 22:06
  • 1
    I've also Included info on how to parse using the slice method.
    – Ritzy Dev
    Commented Jan 6, 2023 at 22:10

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.