# Same-address tokens

### What Are Same-Address Tokens?

If you want to have a cross-chain token (two separate token smart contracts connected by a bridge), it is sometimes important to keep the same addresses for both. This can have benefits such as:

* Easier bridge setup
* Proof to users that it is the same token across chains
* Simplified integration for wallets and exchanges

### How It Works

We've enabled this feature by using a hybrid contract initialization approach. Instead of only using the constructor in the token smart contract, we also include an initializer - a public function that can be run only once to set up the core functionality of the token.

Although this method isn't mandatory when users deploy tokens directly from their wallet, it's necessary in our case. We use the CREATE2 opcode to maintain the same token address even if some parameters are changed in the bytecode.

## Prerequisites

{% hint style="warning" %}
**These requirements must be met to obtain same-address tokens:**

1. Both tokens must be generated using the 20lab generator v. 1.6.0 or higher.
2. Both tokens must be generated with **EXACTLY THE SAME** parameters, except for:

   * **Default exchange**: Only the "Token integration template" must be the same (see [supported exchanges documentation](https://docs.20lab.app/decentralized-exchanges/supported-exchanges))
   * **Custom token for wallet taxes**: Can be different between chains
   * **Custom token for dividends**: Can be different between chains

   The above 3 parameters can be different in both tokens and won't affect the token address in any way.
   {% endhint %}

{% hint style="info" %}
Both tokens should ideally be generated using the same generator version, but this is not mandatory - in many cases, different generator versions can still produce the same addresses.
{% endhint %}

### Step-by-Step Process

#### Step 1: Deploy Your First Token

Deploy the first token on [20lab.app](https://20lab.app/) by choosing your features, compiling it, and creating it on the first blockchain where you want it to exist.

<figure><img src="https://2227986809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiXsnL20jyBNNxpiEbHVU%2Fuploads%2FaeXB47pZfJWOfTpjjIM8%2Fimage.png?alt=media&#x26;token=094bcbe2-5c72-471c-9829-2e709c62105a" alt=""><figcaption></figcaption></figure>

#### Step 2: Modify Address (Optional)

After compilation, you can optionally change the address by modifying the salt or searching for a desired pattern in the token address.

#### Step 3: Get Creation Details

After successful deployment, go to your dashboard and you will see an info icon below your token address. Click on it to see the creation details.

<figure><img src="https://2227986809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiXsnL20jyBNNxpiEbHVU%2Fuploads%2FOWZfCjqESMaGJ0uva7Sn%2FOnPaste.20240314-124758.png?alt=media&#x26;token=bd7db33d-6df2-4975-abc9-a8a493c18db6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2227986809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiXsnL20jyBNNxpiEbHVU%2Fuploads%2FfIpryYFntAD1QXoP3fbW%2Fimage.png?alt=media&#x26;token=202cffec-c5f0-4756-a008-b2130e68c646" alt=""><figcaption></figcaption></figure>

#### Step 4: Copy the Salt

Copy and save the "Salt" value from the creation details. You'll need this for your second token.

### Creating the Second Token

#### Step 1: Start Second Token Creation

Begin creating the second token on a different blockchain.

<figure><img src="https://2227986809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiXsnL20jyBNNxpiEbHVU%2Fuploads%2FoieUYrUgOZTce8kmo75O%2Fimage.png?alt=media&#x26;token=34183d5f-0ec9-4515-af50-5d131a56716a" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**Important:** Keep all the parameters exactly the same as in the first token, because all of them will affect the address of your next token (with the few exceptions listed in the Prerequisites section).
{% endhint %}

This is intentional behavior to prevent others from creating another token at the same address as yours. Because the parameters must be identical, no one can insert their own owner address or add a recipient - this would change the token address completely.

#### Step 2: Validate and Use Salt

Validate your token configuration and select the 'Modify by salt' option.

<figure><img src="https://2227986809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiXsnL20jyBNNxpiEbHVU%2Fuploads%2FQlYf1CILKvds2DvTLotS%2Fimage.png?alt=media&#x26;token=dfb84238-9867-45c7-92e0-c7d8982f53d7" alt=""><figcaption></figcaption></figure>

Paste the copied salt from your first token and check if your token address matches the first token's address.

<figure><img src="https://2227986809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiXsnL20jyBNNxpiEbHVU%2Fuploads%2FawiwzHezp2rn2uSNYF5k%2Fimage.png?alt=media&#x26;token=096502b2-a21b-4696-b487-b1ba09a3fe53" alt=""><figcaption></figcaption></figure>

If you haven't changed any parameters other than the allowed exceptions, your second token address should be exactly the same as the first one.

#### Step 3: Deploy the Second Token

Deploy your second token with the matching address.

## Success! 👏

You now have both tokens with the same address on two different blockchains.

**Example of successful same-address deployment:**

* Ethereum Goerli: [`0x8960b7E3912B4eb03d8195aC1F0Db9Fdb6B17827`](https://goerli.etherscan.io/token/0x8960b7E3912B4eb03d8195aC1F0Db9Fdb6B17827)&#x20;
* BSC Testnet: [`0x8960b7E3912B4eb03d8195aC1F0Db9Fdb6B17827`](https://testnet.bscscan.com/token/0x8960b7E3912B4eb03d8195aC1F0Db9Fdb6B17827)

<figure><img src="https://2227986809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiXsnL20jyBNNxpiEbHVU%2Fuploads%2F0vJSxCXcf4dr41IfWqB2%2FBez%20nazwy%20(2).png?alt=media&#x26;token=3d42e74d-98bc-46f4-ad23-ff170dc96855" alt=""><figcaption></figcaption></figure>

### Important Security Notes

* **Parameter Verification**: Always double-check that your parameters match exactly (except for the allowed exceptions)
* **Address Validation**: Always verify the address matches before deploying the second token
* **Bridge Setup**: Having the same address simplifies bridge configuration but doesn't automatically create the bridge connection

### Troubleshooting

**If addresses don't match:**

1. Verify all parameters are identical (except allowed exceptions)
2. Check that you're using the correct salt
3. Ensure you're using generator v. 1.6.0 or higher
4. Review that the token integration template for your Default Exchange is the same for both tokens
