Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How Uniswap deployed contract to the same address?
Turbo Panumarch
Turbo Panumarch

Posted on

     

How Uniswap deployed contract to the same address?

The contract address is not random?

I thought all the Ethereum-based contract address was random, just like how we access the wallet from the randomized private key.

Until I found interesting notes from Uniswap v2 Docs.

  1. TheUniswap V2 router address is0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D for all networks.

  2. Moreover,Uniswap LP token address can be deterministicly computed offline.

Wow, These are such a nice dev experience ✨. So I want to explore how they do it.


1. Deploying same contract address to all networks

The address for an Ethereum contract is deterministically computed from the address of its creator (sender) and how many transactions the creator has sent (nonce)

So one simple way is to use the same wallet (address) to deploy all networks, and deploy with the first transaction of the wallet, so nonce will be the same. 🎉

But why?: I think this is quite convenient for the testnet development. The developers have no more need to google for the different testnet address, or make the config handle different addresses.

2. Deploying a pair of tokens LP to the same address.

A new opcode,CREATE2 was added inEIP-1014 that is another way that a contract can be created. For contract created byCREATE2 its address will be:
keccak256( 0xff ++ senderAddress ++ salt ++ keccak256(init_code))[12:]

Considering variable params needed...

  • init_code is a byte code from the deployed contract
  • salt is something which can be changed.

So Uniswap utilizedsalt to be a hash oftoken0 andtoken1 addresses. That's why it is always deterministic. 🎉

Which I think this is also helpful to Uniswap to avoid having a duplicate LP for the same pair of tokens.

But why?: This is quite useful to get the information of each LP without looking up LP address. We just need the addresses of 2 tokens, then compute the LP address to retrieve the information right away.


Thanks to a nice summary from:https://ethereum.stackexchange.com/a/761/76945

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Builder, looking for a way to make an impact through technology. 🚀❤️
  • Location
    Bangkok, Thailand
  • Work
    Web3 Builder & Co-Founder at Flipay
  • Joined

More fromTurbo Panumarch

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp