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

# Constructor

## Modes

There are two modes of operation for the Threat Detector:

* `local`: This mode uses a local database of scam URLs. Use this mode for offline threat detection and testing.
* `cloud`: This mode uses ChainPatrol's cloud service to detect scams.

### Local Mode

To use the local mode, you need to instantiate the `ThreatDetector` class with the `mode` option set to `local`.

```js theme={null}
const detector = new ThreatDetector({
  mode: "local",
});
```

### Cloud Mode

To use the cloud mode, you need to instantiate the `ThreatDetector` class with the `mode` option set to `cloud` and provide your API key.

```js theme={null}
const detector = new ThreatDetector({
  mode: "cloud",
  apiKey: "YOUR_API_KEY",
});
```

## Parameters

<ParamField body="options" type="object" required>
  <Expandable title="properties" defaultOpen>
    <ParamField body="mode" type="'local' | 'cloud'" required>
      The `mode` property controls the mode of operation for the Threat Detector.

      The value of this property can be either `local` or `cloud`.
    </ParamField>

    <ParamField body="apiKey" type="string">
      The `apiKey` property is the API Key for accessing ChainPatrol's APIs. We
      recommend using an environment variable to store your API Key.

      This property is required when the `mode` property is set to `cloud`.
      If `proxyUrl` is set, this property is not required as the proxy server
      will handle the authentication.
    </ParamField>

    <ParamField body="proxyUrl" type="string">
      The `proxyUrl` property is an optional property that can be used to
      specify a proxy URL for accessing ChainPatrol's APIs.

      This property is useful when you are behind a firewall or need to use a
      proxy to access the internet.

      This value is only used when the `mode` property is set to `cloud`.
    </ParamField>

    <ParamField body="redirectUrl" type="string | (url: string) => string">
      The `redirectUrl` property is an optional property that can be used to
      specify a redirect URL for when the detector detects a scam.

      By default, the detector will return the ChainPatrol warning page URL,
      but you can override this by specifying your own URL.

      If you specify a **string**, the string will be used as the redirect URL
      with the scam URL appended as the `originUrl` query parameter:

      ```js theme={null}
      const detector = new ThreatDetector({
        redirectUrl: "https://your-warning-page.com/",
      });
      ```

      If you specify a **function**, the function will be called with the scam URL
      as the first argument:

      ```js theme={null}
      const detector = new ThreatDetector({
        redirectUrl: (url) => {
          return `https://your-warning-page.com/?url=${encodeURIComponent(url)}`;
        },
      });
      ```
    </ParamField>

    <ParamField body="storage" type="Storage">
      The `storage` property is an optional property that can be used to
      specify a custom storage adapter for the detector to cache URL lookups.

      By default, the detector will use the `Storage.memory()` adapter, which
      stores the cache database in memory. This means that the database will be
      cleared when the process exits. If you want to persist the database, you
      can use the `Storage.browser()` adapter, which stores the database in
      local storage, or the `Storage.extension()` adapter, which stores the database
      in the browser's extension storage.
    </ParamField>
  </Expandable>
</ParamField>
