> ## Documentation Index
> Fetch the complete documentation index at: https://docs.neuro-tech.io/llms.txt
> Use this file to discover all available pages before exploring further.

# .NET ContractsClient

> Use the XMPP contract library for identities, templates, contracts, signatures, schemas, and search

`Waher.Networking.XMPP.Contracts.ContractsClient` is the protocol client behind Neuron's contract and Legal Identity workflows. It runs over an authenticated XMPP connection.

## Capability groups

| Group            | Representative operations                                                          |
| ---------------- | ---------------------------------------------------------------------------------- |
| Legal identities | Apply, get, obsolete, mark compromised, add/remove attachments                     |
| Signing          | Sign bytes/streams, validate signatures, choose identity keys                      |
| Trust            | Retrieve trust chain and service providers                                         |
| Contracts        | Create new or from template, get, update, sign, obsolete, delete                   |
| Lists            | Created and signed contract references/objects with pagination                     |
| Schemas          | List schemas and retrieve by namespace/digest                                      |
| Search           | Filter public contracts by XML name/namespace, template, role, parameter, and time |
| Access           | Petition and authorize access to identities/contracts                              |

## Event-based and task-based APIs

The library retains callback overloads for event-driven clients and provides async task helpers for common operations. Prefer task-based APIs in new code and keep the XMPP client's lifetime longer than an individual request.

Conceptual flow:

```csharp theme={null}
Contract contract = await contracts.CreateContractAsync(
    templateId,
    parts,
    parameters,
    ContractVisibility.CreatorAndParts,
    from: null,
    to: null,
    duration: null);

// Render and present the exact returned contract before signing.
string text = await contract.ToMarkdown("en", MarkdownType.ForRendering);

await contracts.SignContract(
    contract,
    role: "Customer",
    transferable: false,
    callback,
    state);
```

Overload signatures vary by library version; compile against the same dependency version used by the target Neuron.

## Connection events

Subscribe to contract proposal, petition, state-change, and signature events before initiating workflows. Event handlers must be idempotent and should fetch the current object rather than trusting an event payload as complete state.

## Error handling

Distinguish transport/IQ errors from a valid response that reports a rejected identity, invalid parameter, or disallowed lifecycle transition. Log contract ID, provider, operation, and stanza error condition—never private keys or protected parameter plaintext.
