> ## 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.

# Quickstart

> Get started using the ChainPatrol SDK in your application

<Note>
  To use the ChainPatrol SDK, you'll need an API key. You can get one by
  emailing [support@chainpatrol.io](mailto:support@chainpatrol.io?subject=Re:%20API%20Key%20for%20SDK\&body=Company:%20%0AName:%20%0APurpose:%20).
</Note>

The most common use-case for using the ChainPatrol SDK is to provide scam
detection in a browser extension-based wallet (ex. Metamask).

The code snippet below shows how to use the SDK in the background script of a
browser extension, demonstrating 4 core concepts:

* Instantiating the `ThreatDetector`
* Listening for navigation events
* Using the `ThreatDetector` to check a URL, and redirecting the user if the URL is
  a scam
* Handling events from the warning page using the Relay class to forward events

<CodeGroup>
  ```js background.js theme={null}
  import { ThreatDetector, Relay, Events, Storage } from "@chainpatrol/sdk";

  // Instantiate the detector
  const detector = new ThreatDetector({
    mode: "cloud",
    apiKey: "YOUR_API_KEY",
    storage: Storage.extension(),
  });

  // Listen for navigation events
  chrome.webNavigation.onBeforeNavigate.addListener(async ({ url, tabId }) => {
    const result = await detector.url(url);
    if (result.ok && result.status === "BLOCKED") {
      // Redirect the user to the warning page
      chrome.tabs.update(tabId, {
        url: result.redirectUrl,
      });
    }
  });

  // Listen for events from the warning page
  Relay.on(Events.ContinueAtOwnRisk, async ({ domain }) => {
    await detector.ignore(domain);
  });
  ```

  ```js content.js theme={null}
  import { Relay, Events } from "@chainpatrol/sdk";

  Relay.run([Events.ContinueAtOwnRisk]);
  ```

  ```js warning.js theme={null}
  import { Relay, Events } from "@chainpatrol/sdk";

  Relay.send(Events.ContinueAtOwnRisk, { domain: "example.com" });
  ```
</CodeGroup>

These concepts are generally applicable to other environments as well. For example
if you're using the SDK in a messaging web application, instead of listening for
navigation events using `chrome.webNavigation`, you would listen for navigation
events for links clicked in the application, or you could instead wait until the
user initiates a transaction and check the URL that initiated the transaction.

The next sections of the documentation will go into more detail about the
different classes exported by the SDK, and how to use them.
