# Creating pairs

> Note that creating a pair for two tokens that already exists would lead to a panic!

## Creating an AZERO/PSP22 Pair

To create an AZERO/PSP22 pair, we can use the following approach:

```rust
fn create_azero_pair(&self, psp22_token:AccountId) -> AccountId {
    let salt_int = ADDRESS_SALTING_INTEGER;
    let azero_pair: Result<Result<AccountId, LangError>, Error> = build_call::<DefaultEnvironment>()
        .call_type(Call::new().callee(ROUTER_ADDRESS))
        .exec_input(
            ExecutionInput::new(Selector::new(
                [0x23, 0xc6, 0xff, 0xad]
            ))
            .push_arg(psp22_token)
            .push_arg(salt_int)
        )
        .call_flags(CallFlags::default().set_allow_reentry(true)) //Ignore this line or set to false if it's not a reentrant call
        .returns::<Result<AccountId, LangError>>()
        .fire();
    
    match azero_pair {
        Err(_) => {
            panic!("Failed call")
        }
        Ok(Err(_)) => {
            panic!("Failed call")
        }
        Ok(Ok(_address)) => return _address
    }
}
```

## Creating a PSP22/PSP22 Pair

To create a PSP22/PSP22 pair, we can use the following approach:

```rust
fn create_azero_pair(&self, psp22_token_a:AccountId, psp22_token_b:AccountId) -> AccountId {
    let salt_int = ADDRESS_SALTING_INTEGER;
    let psp22_pair: Result<Result<AccountId, LangError>, Error> = build_call::<DefaultEnvironment>()
        .call_type(Call::new().callee(ROUTER_ADDRESS))
        .exec_input(
            ExecutionInput::new(Selector::new(
                [0x50, 0x49, 0x5b, 0x96]
            ))
            .push_arg(psp22_token_a)
            .push_arg(psp22_token_b)
            .push_arg(salt_int)
        )
        .call_flags(CallFlags::default().set_allow_reentry(true)) //Ignore this line or set to false if it's not a reentrant call
        .returns::<Result<AccountId, LangError>>()
        .fire();
    
    match psp22_pair {
        Err(_) => {
            panic!("Failed call")
        }
        Ok(Err(_)) => {
            panic!("Failed call")
        }
        Ok(Ok(_address)) => return _address
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://andromeda-swap.gitbook.io/andromedaswap-documentation/ink-developers-guide/creating-pairs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
