Getting Started

Install the Clarity SDK

npm i @claritydao/clarity-sdk

Initialize the Clarity SDK

Before you can make use of the Clarity SDK, you must initialize it somewhere in your app.

It must be initialized somewhere on your front-end. For example, we initialize it in a useEffect on the home page of our example app. And then it can be called throughout the front-end without having to reinitialize.

It must also be initialized on your back-end depending on what functions you are calling. Any functions that interact with the Clarity API require a Clarity API key. As a result, these functions should only be called from the back-end to prevent leaking of the API key. Keep in mind that if you use a framework such as Next.js which uses serverless functions to act as a back-end, you will need to initialize the SDK in each serverless function that you wish to use the SDK in.

```typescriptreact
await ClaritySDK.initialize(
        process.env.NEXT_PUBLIC_BLOCKCHAIN_NETWORK as Networks, // "preview" or "mainnet"
        "Clarity"
      );
```

The following 3 parameters are required to initialize the app:

  1. The network you wish to use: "mainnet" or "preview"

  2. The ID of your DAO as seen in the URL of your DAO's homepage on Clarity

  3. An environment variable called "CLARITY_SDK_API_KEY" that holds the API key for your specific organization.

Example App

A very basic Next.js app utilizing the Clarity SDK is hosted on our GitHub.

NOTE: This is not an interactive app. A useful interactive example app would be difficult as everybody has individual stakes and proposals are constantly advancing through their lifecycle. However, in the repository you can see examples of all the different functions and how to properly pass in the various parameters.

Last updated