# Composing Modules

The following functions support the usage Eligibility/Toggle modules that compose other existing modules with "and"/"or" logical operations. Check out the documentation [here](/for-developers/hats-modules/building-hats-modules/about-module-chains.md) to learn more.

### Create New Eligibility/Toggle Chains

### <mark style="color:purple;">createEligibilitiesChain</mark>

Create a new eligibilities chain module.&#x20;

```typescript
const createInstanceResult = await hatsModulesClient.createEligibilitiesChain({
    account,
    hatId,
    numClauses,
    clausesLengths,
    modules,
    saltNonce,
});
```

***Arguments***:

```typescript
{
    account: Account | Address;
    hatId: bigint;
    numClauses: number;
    clausesLengths: number[];
    modules: `0x${string}`[];
    saltNonce?: bigint;
}
```

* `account` - Viem account (Address for JSON-RPC accounts or Account for other types).
* `hatId` - The hat ID for which the module is created.
* `numClauses` - Number of conjunction clauses.
* `clausesLengths` - Length of each clause.
* `modules`- Array of module instances to chain, at the order corresponding to the provided clauses.
* `saltNonce` - Optional salt nonce to use. If not provided, will be randomly generated.

***Response***:

```typescript
{
  status: "success" | "reverted";
  transactionHash: `0x${string}`;
  newInstance: `0x${string}`;
}
```

* `status` - "success" if transaction was successful, "reverted" if transaction reverted.
* `transactionHash` - transaction's hash.
* `newInstance` - In case of success, the address of the new chain module instance.

### <mark style="color:purple;">createTogglesChain</mark>

Create a new toggles chain module.

```typescript
const createInstanceResult = await hatsModulesClient.createTogglesChain({
    account,
    hatId,
    numClauses,
    clausesLengths,
    modules,
    saltNonce,
});
```

***Arguments***:

```typescript
{
    account: Account | Address;
    hatId: bigint;
    numClauses: number;
    clausesLengths: number[];
    modules: `0x${string}`[];
    saltNonce?: bigint;
}
```

* `account` - Viem account (Address for JSON-RPC accounts or Account for other types).
* `hatId` - The hat ID for which the module is created.
* `numClauses` - Number of conjunction clauses.
* `clausesLengths` - Length of each clause.
* `modules`- Array of module instances to chain, at the order corresponding to the provided clauses.
* `saltNonce` - Optional salt nonce to use. If not provided, will be randomly generated.

***Response***:

```typescript
{
  status: "success" | "reverted";
  transactionHash: `0x${string}`;
  newInstance: `0x${string}`;
}
```

* `status` - "success" if transaction was successful, "reverted" if transaction reverted.
* `transactionHash` - transaction's hash.
* `newInstance` - In case of success, the address of the new chain module instance.

### Read From Eligibility/Toggle Chains

The following functions support reading from chain module instances.&#x20;

### <mark style="color:purple;">getRulesets</mark>

Get the rulesets of a module instance.

A ruleset is an array of modules which are chained together with an "AND" logical operator. If the module is a chain with multiple rulesets, then these rulesets are chained together with an "OR" logical operator.

If the provided address is a single module instance (not a chain), then the result will be a single ruleset, which will consist of the single module instance.

```typescript
const rulesets = await hatsModulesClient.getRulesets(address);
```

***Arguments***:

```typescript
`0x${string}`
```

Instance address.

***Response***:

```typescript
Ruleset[] | undefined
```

The module's [rulesets](/for-developers/hats-modules/modules-sdk/types.md#ruleset), or `undefined` if the provided address is not a module.

### <mark style="color:purple;">getRulesetsBatched</mark>

Get the rulesets of multiple module instances.

A ruleset is an array of modules which are chained together with an "AND" logical operator. If the module is a chain with multiple rulesets, then these rulesets are chained together with an "OR" logical operator.

If the provided address is a single module instance (not a chain), then the result will be a single ruleset, which will consist of the single module instance.

```typescript
const rulesets = await hatsModulesClient.getRulesetsBatched(addresses);
```

***Arguments***:

```typescript
`0x${string}`[]
```

Array of instance addresses.

***Response***:

```typescript
(Ruleset[] | undefined)[]
```

For each module instance, returns the module's [rulesets](/for-developers/hats-modules/modules-sdk/types.md#ruleset), or `undefined` if the provided address is not a module.

### <mark style="color:purple;">isChain</mark>

Check whether a module instance is a modules chain.

```typescript
const isChain = await hatsModulesClient.isChain(address);
```

***Arguments***:

```typescript
`0x${string}`
```

Instance address.

***Response***:

```typescript
boolean
```

`true` if the instance is a chain, `false` otherwise.

### <mark style="color:purple;">isChainBatched</mark>

Check whether multiple module instances are modules chains.

```typescript
const isChainBatched = await hatsModulesClient.isChainBatched(addresses);
```

***Arguments***:

```typescript
`0x${string}`[]
```

Instance addresses.

***Response***:

```typescript
boolean[]
```

For each instance, `true` if the instance is a chain, `false` otherwise.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hatsprotocol.xyz/for-developers/hats-modules/modules-sdk/composing-modules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
