> ## Documentation Index
> Fetch the complete documentation index at: https://thrackle.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# createRule

> **createRule**(`config`, `rulesEnginePolicyContract`, `rulesEngineRulesContract`, `rulesEngineComponentContract`, `rulesEngineForeignCallContract`, `policyId`, `ruleS`, `foreignCallNameToID`, `trackerNameToID`): `Promise`\<`number`>

Asynchronously creates a new rule in the rules engine policy contract.

## Parameters

| Parameter                                | Type                                                   | Description                                                         |
| ---------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------- |
| `config`                                 | `Config`                                               | -                                                                   |
| `rulesEnginePolicyContract`              | `object`                                               | -                                                                   |
| `rulesEnginePolicyContract.abi`          | (`object` \| `object`)\[]                              | -                                                                   |
| `rulesEnginePolicyContract.address`      | \`0x\$\{string}\`                                      | -                                                                   |
| `rulesEngineRulesContract`               | `object`                                               | The contract instance for interacting with the rules engine policy. |
| `rulesEngineRulesContract.abi`           | (`object` \| `object` \| `object`)\[]                  | -                                                                   |
| `rulesEngineRulesContract.address`       | \`0x\$\{string}\`                                      | -                                                                   |
| `rulesEngineComponentContract`           | `object`                                               | -                                                                   |
| `rulesEngineComponentContract.abi`       | (`object` \| `object` \| `object`)\[]                  | -                                                                   |
| `rulesEngineComponentContract.address`   | \`0x\$\{string}\`                                      | -                                                                   |
| `rulesEngineForeignCallContract`         | `object`                                               | -                                                                   |
| `rulesEngineForeignCallContract.abi`     | (`object` \| `object` \| `object`)\[]                  | -                                                                   |
| `rulesEngineForeignCallContract.address` | \`0x\$\{string}\`                                      | -                                                                   |
| `policyId`                               | `number`                                               | The ID of the policy to which the rule belongs.                     |
| `ruleS`                                  | `string`                                               | A JSON string representing the rule to be created.                  |
| `foreignCallNameToID`                    | [`FCNameToID`](../../types/type-aliases/FCNameToID)\[] | An array mapping foreign call names to their corresponding IDs.     |
| `trackerNameToID`                        | [`FCNameToID`](../../types/type-aliases/FCNameToID)\[] | An array mapping tracker names to their corresponding IDs.          |

## Returns

`Promise`\<`number`>

A promise that resolves to the result of the rule creation operation. Returns the rule ID if successful, or -1 if the operation fails.

## Throws

Will log errors to the console if the contract simulation fails and retry the operation after a delay.

## Remarks

* The function parses the rule JSON string to build the rule and effect structures.
* It uses a retry mechanism with a delay to handle potential failures during contract simulation.
* If the rule creation is successful, it writes the contract, generates a rule modifier, and optionally injects the modifier into the specified contract.

## Defined in

[src/modules/rules.ts:73](https://github.com/forte-service-company-ltd/forte-rules-engine-sdk/blob/5aad4d7c3c8cc91280e4449c17ac8ea31219fbed/src/modules/rules.ts#L73)
