> For the complete documentation index, see [llms.txt](https://nostraswap.gitbook.io/nostraswap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nostraswap.gitbook.io/nostraswap/protocol/smart-contract-architecture/nostraswapfactory.md).

# NostraSwapFactory

## Code

//add link to code

## Address

//add address of factory contract

## Events <a href="#events" id="events"></a>

### PairCreated <a href="#paircreated" id="paircreated"></a>

```
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
```

Emitted each time a pair is created via [createPair](https://uniswap.org/docs/v2/smart-contracts/factory/#createpair).

* `token0` is guaranteed to be strictly less than `token1` by sort order.
* The final `uint` log value will be `1` for the first pair created, `2` for the second, etc. (see allPairs/getPair).

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### getPair <a href="#getpair" id="getpair"></a>

```
function getPair(address tokenA, address tokenB) external view returns (address pair);
```

Returns the address of the pair for `tokenA` and `tokenB`, if it has been created, else `address(0)` (`0x0000000000000000000000000000000000000000`).

* `tokenA` and `tokenB` are interchangeable.
* Pair addresses can also be calculated deterministically.

### allPairs <a href="#allpairs" id="allpairs"></a>

```
function allPairs(uint) external view returns (address pair);
```

Returns the address of the `n`th pair (`0`-indexed) created through the factory, or `address(0)` (`0x0000000000000000000000000000000000000000`) if not enough pairs have been created yet.

* Pass `0` for the address of the first pair created, `1` for the second, etc.

### allPairsLength <a href="#allpairslength" id="allpairslength"></a>

```
function allPairsLength() external view returns (uint);
```

Returns the total number of pairs created through the factory so far.

### feeTo <a href="#feeto" id="feeto"></a>

```
function feeTo() external view returns (address);
```

Set the fee recipient. Initially set to `address(0)` , meaning all 0.3% fees go to liquidity providers.

### feeToSetter <a href="#feetosetter" id="feetosetter"></a>

```
function feeToSetter() external view returns (address);
```

The address allowed to change [feeTo](https://uniswap.org/docs/v2/smart-contracts/factory/#feeto).

## State-Changing Functions <a href="#state-changing-functions" id="state-changing-functions"></a>

### createPair <a href="#createpair" id="createpair"></a>

```
function createPair(address tokenA, address tokenB) external returns (address pair);
```

Creates a pair for `tokenA` and `tokenB` if one doesn’t exist already.

* `tokenA` and `tokenB` are interchangeable.
* Emits [PairCreated](https://uniswap.org/docs/v2/smart-contracts/factory/#paircreated).

## Interface <a href="#interface" id="interface"></a>

```
pragma solidity >=0.5.0;

interface INostraSwapFactory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);
    function owner() external view returns (address);
    function externalFactory0() external view returns (address);
    function externalFactory1() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
    function setOwner(address) external;
    function setExternalFactories(address, address) external;
}

```

## ABI <a href="#abi" id="abi"></a>

//add ABI
