Skip to content

Encode_Permit2_Permit

Elnaril edited this page Oct 13, 2026 · 1 revision

How to encode a Permit2 permit ?

The Universal Router can be given a token allowance through the Permit2 contract (0x000000000022D473030F116dDEE9F6B43aC78BA3) using an off-chain signature instead of a regular on-chain approve. This is done with the PERMIT2_PERMIT function.

⚠ The Permit2 contract itself must first be approved through the token contract.

Codec creation

An rpc access is required to fetch the current Permit2 allowance and nonce:

from uniswap_universal_router_decoder import RouterCodec
rpc_endpoint = "https://..."  # your rpc endpoint
codec = RouterCodec(rpc_endpoint=rpc_endpoint)  # or RouterCodec(w3=w3)

Fetching the current allowance, expiration and nonce

The Permit2 nonce, needed to build the permit, can be fetched like that:

amount, expiration, nonce = codec.fetch_permit2_allowance(account.address, token_address)

Creating the signable message

data, signable_message = codec.create_permit2_signable_message(
    token_address,  # the token the allowance is given for
    amount,  # the allowance amount in Wei, max = 2 ** 160 - 1
    expiration,  # the unix timestamp at which the allowance becomes invalid
    nonce,  # the Permit2 nonce, see above
    ur_address,  # the spender: the UR checksum address
    deadline,  # the deadline of the permit signature
    chain_id,  # the chain id, ex: 1 for Ethereum Mainnet
)

Signing and encoding

The signable message must be signed with your account:

signed_message = account.sign_message(signable_message)  # where account is your LocalAccount

Then the permit can be encoded:

encoded_data = codec.encode.chain().permit2_permit(data, signed_message).build(deadline)

# then in your transaction dict:
transaction["data"] = encoded_data

# you can now sign and send the transaction to the UR

Ending words

The permit can also be chained with a swap in the same transaction. See How to chain several commands in the same transaction ?.

A full working example is available in this tutorial.

Clone this wiki locally