# Contract templates

> Contract templates on NeuroChain — publishing a template from a validator, describing its interface (constructor fields and functions with descriptions) in the ABI JSON, what users see without one, and the template's security score.

Source: https://docs.nro.world/build/templates

A template is reusable contract bytecode in the on-chain registry. Anyone can deploy a contract from it in the cabinet's **Market**; the template's interface tells the cabinet which fields to ask for at deploy time and which functions to offer on the contract's page.

## Publish a template

Only a `.node` (validator) address can publish (**Market → Create Template**, or `POST /api/v1/templates/register` signed by the node's owner key). You give:

| Field | Required | Notes |
|---|---|---|
| Template name | yes | Shown on the Market card |
| Description | no | One or two sentences on what the contract does |
| Usage royalty (NRO) | no | Paid to you each time someone deploys from the template (0 = free) |
| WASM bytecode | yes | Upload the `.wasm` or paste its hex (`0061736d…`) |
| Interface (ABI) | no, but recommended | Constructor fields and functions, see below |

The template id is the SHA3 hash of the bytecode, so the same bytecode cannot be registered twice. To publish a changed interface for the same bytecode, retire the template (author only) and register it again.

## Describe the interface

Build it in the visual editor (**+ Field**, **+ Method**; each method has a one-sentence description field) or switch to **{ } Raw JSON** and paste an object with two lists:

```json
{
  "init_params": [
    { "name": "seller", "label": "Seller address", "type": "text", "required": true,
      "placeholder": "neuro:seller.human",
      "note": "Who receives the NRO when the deal is released" }
  ],
  "methods": [
    { "name": "release", "label": "Release to the seller", "type": "write",
      "description": "Pay the escrowed amount to the seller and close the deal.",
      "args": [] },
    { "name": "balance_of", "label": "Balance Of", "type": "read",
      "description": "How many tokens an address holds.",
      "args": [ { "name": "address", "label": "Address", "type": "text" } ] }
  ]
}
```

**Constructor fields** (`init_params`) are the deploy form. Their values are passed to the contract's `initialize` function right after the deploy.

| Key | Meaning |
|---|---|
| `name` | Argument name the contract reads |
| `label` | Field title in the deploy form |
| `type` | `text` or `number` |
| `required` | The deploy button waits until it is filled |
| `placeholder`, `default`, `min`, `max`, `maxlength` | Input hints and limits |
| `note` | One line under the field explaining it |

**Functions** (`methods`) are what users can call once the contract exists.

| Key | Meaning |
|---|---|
| `name` | Exact function name in the contract |
| `label` | Title the user sees |
| `description` | One sentence on what the function does — shown on the deploy page ("What this contract can do") and on the contract page |
| `type` | `read` (free, no transaction) or `write` (a signed transaction, uses gas) |
| `args` | Arguments, each `{ "name", "label", "type" }` (`text` or `number`) |
| `ownerOnly` | `true` hides the function from everyone but the contract owner |

The repository's templates are complete examples: `neurochain/contracts/dao/dao.abi.json`, `gov_dao/gov_dao.abi.json`, `escrow/escrow.abi.json`.

## Without an interface

Publishing works with bytecode alone; the interface is stored as `[]`. Then:

- the deploy page has no constructor fields, so the contract is deployed **without** `initialize`. A contract that needs it stays uninitialized until its deployer calls `initialize` (other callers are refused by well-written contracts — the repo's templates check the deployer);
- the deploy page cannot list what the contract can do;
- the contract page has no ready-made forms — only the generic **Call Contract** panel: the user types a function name and its arguments as a JSON object and presses **Read (dry)** or **Write (TX)**. It works, but the user has to know the function names and arguments;
- the Market card shows 0 methods.

## Security score

Every template card shows the score its deploy would get — the same verdict the validators apply at deploy:

- **reviewed** — the bytecode is on the validators' whitelist: score 100, no analysis;
- otherwise VMGuardian analyses the bytecode and lists its findings (rule and severity: critical, warning, info). A deploy whose risk reaches the network threshold is refused.

Every deployed contract gets a **security certificate** in the deploy itself: the score it passed with, its level (Gold, Silver, Bronze), the bytecode hash and VMGuardian's findings, issued by `neuro:vmguardian.cert`. When a release updates the analyzer, the chain re-scores every contract and re-issues the certificates whose score moved.

The reentrancy rule flags a function that writes storage after calling another contract (`call_contract`) on the same path; apply your own state changes before external calls (checks-effects-interactions).
