<!-- Generated from the function registry (sdk/src/functions) by `cd sdk && npm run gen`. Do not edit. -->

# Contracts

> **Status:** Current (generated)

Interfaces and published code; deploy, create, call and view any contract by its `.mxi` interface. `contract.open` adds one function per entry of a deployed contract.

| Function | Kind | Description |
|---|---|---|
| [`contract.interface`](#contractinterface) | read | A deployed contract's published interface: code hash, domain, creator, name, `.mxi` source, constants (hex) and the validated interface (MXE hex) |
| [`contract.code`](#contractcode) | read | Published code by standard name (mrc20, exchange, staking) or code hash, with its interface (MXE hex) |
| [`contract.query`](#contractquery) | read | Run any entry read-only against the latest state, with raw MXE input and output (contract.view encodes them by the interface) |
| [`contract.open`](#contractopen) | read | Load a deployed contract by address and generate one function per entry of its interface: `<alias>.<entry>` (views read, fns prepare a transaction) |
| [`contract.view`](#contractview) | read | Call a view by name with JSON arguments, encoded and decoded by the contract's interface |
| [`contract.call`](#contractcall) | write | Prepare a call to a state-changing function by name, with JSON arguments encoded by the interface: an unsigned transaction and a summary for the sender's wallet |
| [`contract.deploy`](#contractdeploy) | write | Prepare publishing and creating a contract from a WebAssembly module and its `.mxi` interface (default: the one embedded in the module), with typed init arguments |
| [`contract.create`](#contractcreate) | write | Prepare creating a contract from published code (a standard name such as mrc20, or a code hash), with init arguments encoded by its interface |

## contract.interface

A deployed contract's published interface: code hash, domain, creator, name, `.mxi` source, constants (hex) and the validated interface (MXE hex). Null if there is no contract there.

- **Kind:** read
- **Runs:** JSON-RPC `mox_interface` (`POST /`) on the gateway

**Input**

| Field | Type | Required | Description |
|---|---|---|---|
| `contract` | hex32 | yes | Contract: 32 bytes, 0x hex |

**Output**

An object (or null).

| Field | Type | Required | Description |
|---|---|---|---|
| `code_hash` | hex |  | Code: 0x hex |
| `domain` | integer |  | Domain |
| `creator` | hex |  | Creator: 0x hex |
| `name` | string |  | Name |
| `source` | string |  | .mxi source |
| `constants` | object |  |  |
| `interface` | hex |  | Interface (MXE): 0x hex |

## contract.code

Published code by standard name (mrc20, exchange, staking) or code hash, with its interface (MXE hex).

- **Kind:** read
- **Runs:** JSON-RPC `mox_code` (`POST /`) on the gateway

**Input**

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | string |  | A standard code's name |
| `hash` | hex32 |  | A code hash: 32 bytes, 0x hex |

**Output**

An object.

| Field | Type | Required | Description |
|---|---|---|---|
| `hash` | hex or null |  |  |
| `interface` | hex or null |  |  |

**Example**

```json
{
  "name": "contract.code",
  "input": {
    "name": "mrc20"
  }
}
```

## contract.query

Run any entry read-only against the latest state, with raw MXE input and output (contract.view encodes them by the interface).

- **Kind:** read
- **Runs:** JSON-RPC `mox_query` (`POST /`) on the gateway

**Input**

| Field | Type | Required | Description |
|---|---|---|---|
| `contract` | hex32 | yes | Contract: 32 bytes, 0x hex |
| `entry` | string | yes | Entry name |
| `input` | hex | yes | MXE-encoded arguments: 0x hex |

**Output**

An object.

| Field | Type | Required | Description |
|---|---|---|---|
| `status` | integer |  |  |
| `output` | hex |  | Raw output: 0x hex |

## contract.open

Load a deployed contract by address and generate one function per entry of its interface: `<alias>.<entry>` (views read, fns prepare a transaction).

- **Kind:** read
- **Runs:** SDK (`@mox/sdk/functions`), MCP and `mox fn`: built from other calls

**Input**

| Field | Type | Required | Description |
|---|---|---|---|
| `address` | hex32 | yes | Contract: 32 bytes, 0x hex |
| `alias` | string |  | Name prefix for its functions (default: the contract's name, lowercased) |

**Output**

An object.

| Field | Type | Required | Description |
|---|---|---|---|
| `address` | hex |  | Contract: 0x hex |
| `alias` | string |  | Prefix |
| `name` | string |  | Contract name |
| `functions` | array of object |  |  |
| `constants` | object |  |  |

## contract.view

Call a view by name with JSON arguments, encoded and decoded by the contract's interface. Free, needs no wallet.

- **Kind:** read
- **Runs:** SDK (`@mox/sdk/functions`), MCP and `mox fn`: built from other calls

**Input**

| Field | Type | Required | Description |
|---|---|---|---|
| `contract` | hex32 | yes | Contract: 32 bytes, 0x hex |
| `entry` | string | yes | View name |
| `args` | array of any or object |  | Arguments as JSON: an array in order, or an object by name (see the interface; amounts in the token's decimals) |

**Output**

any: Any JSON value.

## contract.call

Prepare a call to a state-changing function by name, with JSON arguments encoded by the interface: an unsigned transaction and a summary for the sender's wallet.

- **Kind:** write: returns an unsigned transaction and a summary; a wallet signs it
- **Runs:** SDK (`@mox/sdk/functions`), MCP and `mox fn`: built from other calls

**Input**

| Field | Type | Required | Description |
|---|---|---|---|
| `from` | hex32 |  | Sender: the account that will sign (default: the configured account). Its sequence number and the snapshot are read now: 32 bytes, 0x hex |
| `contract` | hex32 | yes | Contract: 32 bytes, 0x hex |
| `entry` | string | yes | Function name |
| `args` | array of any or object |  | Arguments as JSON: an array in order, or an object by name (see the interface; amounts in the token's decimals) |
| `value` | array of [hex32, string or integer] |  | Tokens to attach, moved to the contract before it runs: [token address, base units] |

**Output**

An object: An unsigned prepared transaction.

| Field | Type | Required | Description |
|---|---|---|---|
| `summary` | string |  | What the transaction does, for the person approving it |
| `from` | hex32 |  | Sender: 32 bytes, 0x hex |
| `unsigned` | object |  | The transaction as mox-client describes it (crates/mox-client/src/tx.rs), unsigned: chain_id, seq, snapshot, class, domain, limits, payload, value, fee |
| `request` | object or null |  |  |
| `max_fee` | decimal string |  | The most it can cost at current prices (its declared limits); unused fees are refunded |
| `next` | string |  | How to finish: sign, then tx.submit |

## contract.deploy

Prepare publishing and creating a contract from a WebAssembly module and its `.mxi` interface (default: the one embedded in the module), with typed init arguments. The receipt's output is the new address.

- **Kind:** write: returns an unsigned transaction and a summary; a wallet signs it
- **Runs:** SDK (`@mox/sdk/functions`), MCP and `mox fn`: built from other calls

**Input**

| Field | Type | Required | Description |
|---|---|---|---|
| `from` | hex32 |  | Sender: the account that will sign (default: the configured account). Its sequence number and the snapshot are read now: 32 bytes, 0x hex |
| `module` | hex | yes | The WebAssembly module: 0x hex |
| `interface` | string |  | The `.mxi` source (default: embedded in the module) |
| `init` | array of any or object |  | Arguments as JSON: an array in order, or an object by name (see the interface; amounts in the token's decimals) |
| `salt` | hex32 |  | Salt for the contract address (default: random): 32 bytes, 0x hex |
| `domain` | integer |  | Domain |

**Output**

An object: An unsigned prepared transaction.

| Field | Type | Required | Description |
|---|---|---|---|
| `summary` | string |  | What the transaction does, for the person approving it |
| `from` | hex32 |  | Sender: 32 bytes, 0x hex |
| `unsigned` | object |  | The transaction as mox-client describes it (crates/mox-client/src/tx.rs), unsigned: chain_id, seq, snapshot, class, domain, limits, payload, value, fee |
| `request` | object or null |  |  |
| `max_fee` | decimal string |  | The most it can cost at current prices (its declared limits); unused fees are refunded |
| `next` | string |  | How to finish: sign, then tx.submit |

## contract.create

Prepare creating a contract from published code (a standard name such as mrc20, or a code hash), with init arguments encoded by its interface.

- **Kind:** write: returns an unsigned transaction and a summary; a wallet signs it
- **Runs:** SDK (`@mox/sdk/functions`), MCP and `mox fn`: built from other calls

**Input**

| Field | Type | Required | Description |
|---|---|---|---|
| `from` | hex32 |  | Sender: the account that will sign (default: the configured account). Its sequence number and the snapshot are read now: 32 bytes, 0x hex |
| `code` | string | yes | Standard code name or code hash |
| `init` | array of any or object |  | Arguments as JSON: an array in order, or an object by name (see the interface; amounts in the token's decimals) |
| `salt` | hex32 |  | Salt (default: random): 32 bytes, 0x hex |
| `domain` | integer |  | Domain |

**Output**

An object: An unsigned prepared transaction.

| Field | Type | Required | Description |
|---|---|---|---|
| `summary` | string |  | What the transaction does, for the person approving it |
| `from` | hex32 |  | Sender: 32 bytes, 0x hex |
| `unsigned` | object |  | The transaction as mox-client describes it (crates/mox-client/src/tx.rs), unsigned: chain_id, seq, snapshot, class, domain, limits, payload, value, fee |
| `request` | object or null |  |  |
| `max_fee` | decimal string |  | The most it can cost at current prices (its declared limits); unused fees are refunded |
| `next` | string |  | How to finish: sign, then tx.submit |

**Example**

```json
{
  "name": "contract.create",
  "input": {
    "from": "0x8c1f6a3e5b2d4c7f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f",
    "code": "mrc20",
    "init": [
      "Gold",
      "GLD",
      2,
      100000,
      null
    ]
  }
}
```
