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

# Factory

The `Factory` contract contains functions to create, buy, sell and launch tokens. This is the main entrypoint of the protocol; creators and traders will mostly interact with this contract.

The user flow of the protocol is:

1. Creator calls `createToken()` to launch a new token.
2. Traders call `buyTokens()` and `sellTokens()` to trade the token.
3. A sufficient amount of tokens is sold and the bonding curve is fulfilled.
4. Anyone calls `launchToken()` to launch the token to Uniswap V2.

### Public Functions

#### createToken

Create a new token with a `name`, `symbol`, `metadata` and a unique `salt`.

Must be called with an amount of ETH equal to or greater than the creation fee; any excess ETH will be used to buy an initial amount of tokens for the creator.

Note that the new token is non-transferable and can only be traded through this contract.

```solidity
function createToken(string memory name, string memory symbol, string memory metadata, bytes32 salt)
    external
    payable
    returns (address tokenAddress, uint256 amountOut)
```

#### buyTokens

Buy tokens in exchange for ETH. Reverts if the amount of tokens received for the ETH provided is less than `minAmountOut`.

```solidity
function buyTokens(address token, uint256 minAmountOut) external payable returns (uint256 amountOut)
```

#### sellTokens

Sell `amountIn` of tokens in exchange for ETH. Reverts if the amount of ETH received is less than `minAmountOut`.

```solidity
function sellTokens(address token, uint256 amountIn, uint256 minAmountOut) external returns (uint256 amountOut)
```

#### launchToken

Launch a token to Uniswap V2. Can only be called when the bonding curve is fulfilled.

Note that the token also becomes transferable post-launch.

```solidity
function launchToken(address token) external returns (address uniswapV2Pair)
```
