# Money

Functions for reading and modifying a player's money on the server.

## getMoney

Get the amount of money a player has of a given type.

```lua
local amount = KOJA.Server.getMoney(source, mtype)
```

| Parameter | Type     | Description                                |
| --------- | -------- | ------------------------------------------ |
| `source`  | `number` | Player server ID                           |
| `mtype`   | `string` | Money type — `"cash"`, `"bank"`, `"black"` |

**Returns** `number`

## addMoney

Add money to a player's account.

```lua
local ok = KOJA.Server.addMoney(source, amount, mtype, reason)
```

| Parameter | Type      | Description                                |
| --------- | --------- | ------------------------------------------ |
| `source`  | `number`  | Player server ID                           |
| `amount`  | `number`  | Amount to add                              |
| `mtype`   | `string`  | Money type — `"cash"`, `"bank"`, `"black"` |
| `reason`  | `string?` | Reason (logged by some frameworks)         |

**Returns** `boolean`

## removeMoney

Remove money from a player's account.

```lua
local ok = KOJA.Server.removeMoney(source, amount, mtype, reason)
```

Same parameters as `addMoney`.

**Returns** `boolean`

## Money Types

| Value     | ESX                   | QBCore              |
| --------- | --------------------- | ------------------- |
| `"cash"`  | `money` account       | `cash` money type   |
| `"bank"`  | `bank` account        | `bank` money type   |
| `"black"` | `black_money` account | `crypto` money type |

## Examples

```lua
-- Read balances
local cash = KOJA.Server.getMoney(source, 'cash')
local bank = KOJA.Server.getMoney(source, 'bank')
print(('Cash: $%d | Bank: $%d'):format(cash, bank))

-- Pay out a reward
KOJA.Server.addMoney(source, 500, 'cash', 'job_reward')

-- Charge for a service
local price = 250
if KOJA.Server.getMoney(source, 'bank') < price then
    KOJA.Server.SendNotify({ source = source, type = 'error', desc = 'Not enough bank balance.' })
    return
end

KOJA.Server.removeMoney(source, price, 'bank', 'shop_purchase')
KOJA.Server.addInventoryItem(source, 'burger', 1)
```

## Related pages

- [Police](/koja-lib/api-reference/server-api/police) — Functions for checking how many police officers are online.
- [Callbacks](/koja-lib/api-reference/server-api/callbacks) — The callback system allows server scripts to handle requests from clients and vice versa.
- [Licenses](/koja-lib/api-reference/server-api/licenses) — Check whether a player holds a specific driving or skill license.
- [Inventory](/koja-lib/api-reference/server-api/inventory) — Server-side inventory functions.
- [Notifications](/koja-lib/api-reference/server-api/notifications) — Send notifications to a player from the server side.
- [Player](/koja-lib/api-reference/server-api/player) — Functions for reading player information on the server.
- [Server API](/koja-lib/api-reference/server-api) — back to the section overview
