Skip to content

Why_Use_The_SDK

Elnaril edited this page Oct 13, 2026 · 2 revisions

Why use the Python Uniswap Universal Router SDK ?

The Uniswap Universal Router (UR) is the entry point used by the official Uniswap UI and many applications and bots. But it is not the easiest contract to work with: it takes a list of commands and their inputs, all packed into a single call, and everything is ABI encoded. Reading or writing that "by hand" is tedious and error prone.

The object of this SDK is to make the UR easy to use with Python, in both directions: decoding what the UR receives, and encoding what you want to send to it.

An SDK dedicated to the Universal Router ...

All SDK features are about UR functions or utilities that help with them.
It will work on all blockchains where the UR is deployed.

... and to its users

The SDK makes the job easier for developers:

  • Strong typing
  • Clear structured decoding output
  • Chaining of the encoding methods
  • Support for async applications
  • Active development to keep track with the UR, Python and web3.py releases
  • Plenty of docs, recipes, tutorials and integration tests

Decode

Give the codec a transaction hash or the raw input data, and it gives you back the commands, their parameters and the deadline, in a readable form. No need to dig into the ABI encoding yourself.

decoded_input = codec.decode.function_input(trx_input)

The codec can also decode a full transaction (codec.decode.transaction()), a V3 path (codec.decode.v3_path()), a V4 pool id and much more.

Encode

The UR allows the chaining of several functions in the same transaction, and the SDK supports it: the encoding methods can be chained one after the other, and the SDK takes care of packing the commands and encoding the parameters for you.

As an illustration, let's say we want to swap ETH for a token in a single transaction, wrapping the ETH first and unwrapping the leftover WETH at the end:

encoded_data = (
    codec
        .encode
        .chain()
        .wrap_eth(FunctionRecipient.ROUTER, amount_in)
        .v3_swap_exact_in(FunctionRecipient.SENDER, amount_in, amount_out_min, path)
        .unwrap_weth(FunctionRecipient.SENDER, 0)
        .build(deadline)
)

All the supported UR functions are available this way: V2, V3 and V4 swaps, ETH wrap/unwrap, Permit2, sweep, transfer, pay portion, sub-plans, ...

Build the full transaction

If you don't want to bother with the transaction parameters, the SDK can build the full transaction for you, computing the gas fees, the nonce, the chain id, ... You just have to sign it and send it.

Sync and async

The library exposes 2 classes, RouterCodec and AsyncRouterCodec, used the same way but either synchronously or asynchronously for the parts doing rpc calls.

Utilities

The SDK also provides a few handy utilities, like computing the gas fees, or the tick, sqrtPriceX96 and liquidity related functions useful to estimate the arguments needed to mint positions.

What it is not

  • It is not a routing or quoting engine (see the uniswap-smart-path lib for that): this UR SDK does not find the best route or price for you, it just encodes and decodes what you give it.
  • It is not a replacement for web3.py: you still need to be familiar with the Ethereum blockchain concepts and web3.py.

Getting started

See How to get started with the Python Uniswap Universal Router SDK ?.

Clone this wiki locally