<!-- Source: https://docs.paxeer.app/modules/tokenfactory/ -->

# Token Factory Module

Permissionless creation and management of native token denominations with namespace protection.

**Source:** `paxeer-network/modules/tokenfactory/`

## Overview

The tokenfactory module allows any account to create new native tokens. Tokens are namespaced by creator address as `factory/&#123;creator address&#125;/&#123;subdenom&#125;`, eliminating name collisions. A single account can create multiple denoms by providing unique subdenoms.

The original creator is granted admin privileges over the token, allowing them to mint, burn, transfer, and change admin.

## Token Naming

Tokenfactory denoms follow the format:

```
factory/{creator_address}/{subdenom}
```

Example:

```
factory/pax166vhptur29s3gw5qr6dm30s06gej6pr4zevkqk/ufoo
```

- **Prefix:** Always `factory` (7 bytes)

- **Creator address:** Bech32 address (max 75 bytes)

- **Subdenom:** User-defined (max 44 bytes, `[a-zA-Z0-9./]`)

Total denom length must not exceed 128 bytes (Cosmos SDK constraint).

## Messages

### CreateDenom

Create a new denom:

```
message MsgCreateDenom {
    string sender = 1;
    string subdenom = 2;
}
```

CLI:

```
paxd tx tokenfactory create-denom ufoo --from mylocalwallet
```

State modifications:

- Set `DenomMetadata` via bank keeper

- Set `AuthorityMetadata` with sender as admin

- Add denom to `CreatorPrefixStore`

### Mint

Mint tokens (admin only):

```
message MsgMint {
    string sender = 1;
    cosmos.base.v1beta1.Coin amount = 2;
}
```

CLI:

```
paxd tx tokenfactory mint 100000000000factory/pax166vh.../ufoo --from mylocalwallet
```

Checks:

- Denom was created via tokenfactory

- Sender is the admin

Mints the specified amount via the bank module.

### Burn

Burn tokens (admin only):

```
message MsgBurn {
    string sender = 1;
    cosmos.base.v1beta1.Coin amount = 2;
}
```

Checks:

- Denom was created via tokenfactory

- Sender is the admin

Burns the specified amount via the bank module.

### ChangeAdmin

Transfer admin privileges:

```
message MsgChangeAdmin {
    string sender = 1;
    string denom = 2;
    string newAdmin = 3;
}
```

The sender must be the current admin. Set `newAdmin` to `""` to renounce admin privileges (irreversible).

## Admin Capabilities

The admin can:

- **Mint:** Create new tokens of the denom

- **Burn:** Destroy tokens from any account

- **Force Transfer:** Move tokens between any two accounts

- **Change Admin:** Transfer or renounce admin rights

Admins can share privileges via the authz module without changing the master admin.

## Queries

### Denom Metadata

```
paxd query bank denom-metadata --denom factory/pax166vh.../ufoo
```

### Denoms by Creator

```
paxd query tokenfactory denoms-from-creator pax166vhptur29s3gw5qr6dm30s06gej6pr4zevkqk
```

## Restrictions

To fit within the 128-byte Cosmos SDK denom limit:

- **Max subdenom length:** 44 characters

- **Max creator address length:** 75 characters (bech32 prefix ≤ 16 chars)

Calculation:

```
len("factory") + 2*len("/") + len(creator_address) + len(subdenom) ≤ 128
7 + 2 + 75 + 44 = 128
```

## Use Cases

- **Wrapped assets:** Mint tokens representing off-chain assets

- **Synthetic tokens:** Create tokens backed by other on-chain assets

- **Protocol-managed denoms:** Modules create denoms for internal accounting

- **Governance tokens:** DAOs issue native governance tokens

## Integration with Bank Module

Tokenfactory denoms are native tokens, not ERC-20 contracts. They integrate with the bank module for:

- Balance queries

- Transfers via `MsgSend`

- IBC transfers

- Distribution to stakers

## EVM Integration

Tokenfactory denoms can be exposed to EVM contracts via [pointer precompiles](https://docs.paxeer.app/precompiles), allowing ERC-20-style interaction from Solidity.

## Next Steps

- [Use precompiles to expose tokenfactory denoms to EVM](https://docs.paxeer.app/precompiles)

- [Review other Paxeer modules](https://docs.paxeer.app/modules)
