> For the complete documentation index, see [llms.txt](https://docs.mosotoscripts.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mosotoscripts.com/scripts/mst_crypto/exports-and-events.md).

# Exports & Events

This section contains all the exports provided by the script. For best results, make changes with someone knowledgeable in Lua to prevent errors.

***

### Server Exports

<details>

<summary><code>GetEconomyIdentifier</code></summary>

```lua
exports['mst_crypto']:GetEconomyIdentifier(src)
```

The **GetEconomyIdentifier** export returns the wallet owner identifier used by Cryptora. If the player is logged into Mining OS, it returns the Cryptora account owner; otherwise it falls back to the character identifier.

**How to use?**

```lua
local identifier = exports['mst_crypto']:GetEconomyIdentifier(source)
print('Economy owner: ' .. tostring(identifier))
```

**Parameters:**

* `src` (number): Player server ID.

**Return value**:

* Returns `string` identifier on success.
* Returns `nil` if the player is invalid.

</details>

<details>

<summary><code>IsLoggedIntoMiningOs</code></summary>

```lua
exports['mst_crypto']:IsLoggedIntoMiningOs(src)
```

The **IsLoggedIntoMiningOs** export checks whether the player currently has an active Cryptora / Mining OS login session.

**How to use?**

```lua
if exports['mst_crypto']:IsLoggedIntoMiningOs(source) then
    print('Player is logged into Cryptora')
else
    print('Player is not logged in')
end
```

**Parameters:**

* `src` (number): Player server ID.

**Return value**:

* Returns `true` if the player has an active OS session.
* Returns `false` otherwise.

</details>

<details>

<summary><code>GetWallets</code></summary>

```lua
exports['mst_crypto']:GetWallets(srcOrIdentifier)
```

The **GetWallets** export returns all crypto balances for a player (or raw identifier).

**How to use?**

```lua
local wallets = exports['mst_crypto']:GetWallets(source)
print(json.encode(wallets, { indent = true }))
-- { ["MST"] = 0.0123, ["K4MB1"] = 15.5 }
```

**Parameters:**

* `srcOrIdentifier` (number|string): Player server ID, or character/economy identifier.

**Return value**:

* Returns `table` of `{ [coin] = balance }`.
* Returns `{}` if none / invalid.

</details>

<details>

<summary><code>GetWalletBalance</code></summary>

```lua
exports['mst_crypto']:GetWalletBalance(srcOrIdentifier, coin)
```

The **GetWalletBalance** export returns the balance of a single coin.

**How to use?**

```lua
local balance = exports['mst_crypto']:GetWalletBalance(source, 'MST')
print(('BTC balance: %s'):format(balance))
```

**Parameters:**

* `srcOrIdentifier` (number|string): Player server ID or identifier.
* `coin` (string): Coin key from `config_coins` (e.g. `'MST'`).

**Return value**:

* Returns `number` balance.
* Returns `0` if missing / invalid coin.

</details>

<details>

<summary><code>HasCoins</code></summary>

```lua
exports['mst_crypto']:HasCoins(srcOrIdentifier, coin, amount)
```

The **HasCoins** export checks whether the wallet has at least the requested amount of a coin.

**How to use?**

```lua
if exports['mst_crypto']:HasCoins(source, 'MST', 0.01) then
    print('Player can pay 0.01 MST')
else
    print('Insufficient MST')
end
```

**Parameters:**

* `srcOrIdentifier` (number|string): Player server ID or identifier.
* `coin` (string): Coin key.
* `amount` (number): Required amount.

**Return value**:

* Returns `true` if balance ≥ amount.
* Returns `false` otherwise.

</details>

<details>

<summary><code>AddCoins</code></summary>

```lua
exports['mst_crypto']:AddCoins(srcOrIdentifier, coin, amount, reason)
```

The AddCoins export credits coins to the Cryptora wallet and writes an `export_add` ledger entry. Coins stay in the crypto wallet (not framework bank).

**How to use?**

```lua
local ok, newBalance = exports['mst_crypto']:AddCoins(source, 'MST', 0.05, 'heist_payout')
if ok then
    print('New balance: ' .. newBalance)
end
```

**Parameters:**

* `srcOrIdentifier` (number|string): Player server ID or identifier.
* `coin` (string): Coin key.
* `amount` (number): Amount to add (must be > 0).
* `reason` (string, optional): Audit reason stored in the transaction meta.

**Return value**:

* Returns `true, newBalance` on success.
* Returns `false, nil` on failure.

</details>

<details>

<summary><code>RemoveCoins</code></summary>

```lua
exports['mst_crypto']:RemoveCoins(srcOrIdentifier, coin, amount, reason)
```

The **RemoveCoins** export debits coins from the Cryptora wallet (e.g. darknet purchase). Fails if the balance is insufficient.

**How to use?**

```lua
local ok, newBalance = exports['mst_crypto']:RemoveCoins(source, 'MST', 0.01, 'darknet_buy')
if ok then
    print('Paid. Remaining: ' .. newBalance)
else
    print('Not enough coins. Balance: ' .. tostring(newBalance))
end
```

**Parameters:**

* `srcOrIdentifier` (number|string): Player server ID or identifier.
* `coin` (string): Coin key.
* `amount` (number): Amount to remove (must be > 0).
* `reason` (string, optional): Audit reason.

**Return value**:

* Returns `true, newBalance` on success.
* Returns `false, currentBalance` if insufficient / invalid.

</details>

<details>

<summary><code>SellCoins</code></summary>

```lua
exports['mst_crypto']:SellCoins(src, coin, amount)
```

The **SellCoins** export sells coins at the live market price into the framework bank account, using the same fees as the Cryptora exchange. The player must be online.

**How to use?**

```lua
local ok, payout = exports['mst_crypto']:SellCoins(source, 'MST', 0.01)
if ok then
    print('Sold for $' .. payout)
else
    print('Sell failed: ' .. tostring(payout)) -- e.g. insufficient, invalid_coin
end
```

**Parameters:**

* `src` (number): Online player server ID (required for bank credit).
* `coin` (string): Coin key.
* `amount` (number): Amount to sell.

**Return value**:

* Returns `true, payout` on success (`payout` is bank money credited).
* Returns `false, error` on failure (`'insufficient'`, `'invalid_coin'`, `'no_player'`, …).

</details>

<details>

<summary><code>GetCoinPrice</code></summary>

```lua
exports['mst_crypto']:GetCoinPrice(coin)
```

The **GetCoinPrice** export returns the current market price of a coin.

**How to use?**

```lua
local price = exports['mst_crypto']:GetCoinPrice('MST')
print('MST price: ' .. price)
```

**Parameters:**

* `coin` (string): Coin key.

**Return value**:

* Returns `number` price.
* Returns `0` if the coin is invalid.

</details>

<details>

<summary><code>GetMarketPrices</code></summary>

```lua
exports['mst_crypto']:GetMarketPrices()
```

The **GetMarketPrices** export returns live prices for all configured coins.

**How to use?**

```lua
local prices = exports['mst_crypto']:GetMarketPrices()
for coin, price in pairs(prices) do
    print(coin, price)
end
```

**Parameters:**

* None.

**Return value**:

* Returns `table` of `{ [coin] = price }`.

</details>

<details>

<summary><code>GetTransactions</code></summary>

```lua
exports['mst_crypto']:GetTransactions(srcOrIdentifier, limit)
```

The **GetTransactions** export returns recent ledger rows (sell/buy, mining, export add/remove, etc.).

**How to use?**

```lua
local txs = exports['mst_crypto']:GetTransactions(source, 20)
for i = 1, #txs do
    print(txs[i].txType, txs[i].coin, txs[i].amount)
end
```

**Parameters:**

* `srcOrIdentifier` (number|string): Player server ID or identifier.
* `limit` (number, optional): Max rows (default \~40, capped at 200).

**Return value**:

* Returns `table` of transaction objects (`id`, `txType`, `coin`, `amount`, `moneyAmount`, `meta`, `createdAt`, …).
* Returns `{}` if none / invalid.

</details>

<details>

<summary><code>GetPlayerMachines</code></summary>

```lua
exports['mst_crypto']:GetPlayerMachines(srcOrIdentifier)
```

The **GetPlayerMachines** export returns serialized mining machines owned by the player’s economy identifier.

**How to use?**

```lua
local machines = exports['mst_crypto']:GetPlayerMachines(source)
print('Machines: ' .. #machines)
```

**Parameters:**

* `srcOrIdentifier` (number|string): Player server ID or identifier.

**Return value**:

* Returns `table` of machine objects.
* Returns `{}` if none.

</details>

<details>

<summary><code>GetMachine</code></summary>

```lua
exports['mst_crypto']:GetMachine(machineId)
```

The **GetMachine** export returns one serialized machine by ID.

**How to use?**

```lua
local machine = exports['mst_crypto']:GetMachine(35)
if machine then
    print(machine.machine_type, machine.powered)
end
```

**Parameters:**

* `machineId` (number): Machine database ID.

**Return value**:

* Returns `table` machine data on success.
* Returns `nil` if not found.

</details>

<details>

<summary><code>GetMachineHashrate</code></summary>

```lua
exports['mst_crypto']:GetMachineHashrate(machineId)
```

The **GetMachineHashrate** export returns the computed hashrate for a machine (same formulas as Mining OS).

**How to use?**

```lua
local hashrate = exports['mst_crypto']:GetMachineHashrate(35)
print('Hashrate: ' .. hashrate)
```

**Parameters:**

* `machineId` (number): Machine database ID.

**Return value**:

* Returns `number` hashrate.
* Returns `0` if the machine is missing / invalid.

</details>
