|
| 1 | +# Hypercert SDK |
| 2 | + |
| 3 | +## Quickstart Guide |
| 4 | + |
| 5 | +1. Install the SDK using npm or yarn: |
| 6 | + |
| 7 | +```bash |
| 8 | +pnpm install @hypercerts-org/sdk |
| 9 | +``` |
| 10 | + |
| 11 | +or |
| 12 | + |
| 13 | +```bash |
| 14 | + pnpm add @hypercerts-org/sdk |
| 15 | +``` |
| 16 | + |
| 17 | +2. Import the SDK into your project: |
| 18 | + |
| 19 | +```bash |
| 20 | +import { HypercertClient } from "@hypercerts-org/sdk"; |
| 21 | +``` |
| 22 | +
|
| 23 | +3. Create a new instance of the HypercertClient class with your configuration options: |
| 24 | +
|
| 25 | +```js |
| 26 | +const client = new HypercertClient({ |
| 27 | + environment: "test", |
| 28 | + walletClient, // optional, client will default to read-only mode if not provided |
| 29 | + publicClient, // optional, can be infered from walletClient if present |
| 30 | +}); |
| 31 | +``` |
| 32 | +
|
| 33 | +> **Note** If there's no `walletClient` provided the client will run in [read-only mode](#read-only-mode) |
| 34 | +
|
| 35 | +4. Use the client object to interact with the Hypercert network. |
| 36 | +
|
| 37 | +For example, you can use the `client.mintClaim` method to create a new claim: |
| 38 | +
|
| 39 | +```ts |
| 40 | +const hash = await client.mintHypercert({ |
| 41 | + metaData: { ... }, |
| 42 | + totalUnits: 1000n, |
| 43 | + transferRestriction: TransferRestrictions.AllowAll, |
| 44 | +}); |
| 45 | +``` |
| 46 | +
|
| 47 | +This will validate the metadata, store it on IPFS, create a new hypercert on-chain and return a transaction receipt. |
| 48 | +
|
| 49 | +For more information on how to use the SDK, check out the |
| 50 | +[developer documentation](https://hypercerts.org/docs/developer/) and the |
| 51 | +[Graph playground](https://thegraph.com/hosted-service/subgraph/hypercerts-admin/hypercerts-testnet). |
| 52 | +
|
| 53 | +That's it! With these simple steps, you can start using the Hypercert SDK in your own projects. |
| 54 | +
|
| 55 | +## Config |
| 56 | +
|
| 57 | +HypercertClientConfig is a configuration object used when initializing a new instance of the HypercertClient. It allows |
| 58 | +you to customize the client by setting your own providers or deployments. At it's simplest, you only need to provide |
| 59 | +`chain.id` to initalize the client in `readonly` mode. |
| 60 | +
|
| 61 | +| Field | Type | Description | |
| 62 | +| -------------- | ------------------------ | -------------------------------------------------------------------------------------------- | |
| 63 | +| `environment` | `'test' \| 'production'` | Defines the environment the client will connect with. | |
| 64 | +| `deployments` | Object | The deployments of the contracts on various networks. | |
| 65 | +| `readOnly` | Boolean | Boolean to assert if the client is in read-only mode. | |
| 66 | +| `graphUrl` | String | The URL of the graph endpoint. | |
| 67 | +| `publicClient` | Object | The `PublicClient` is inherently read-only and is used for reading data from the blockchain. | |
| 68 | +| `walletClient` | Object | The `WalletClient` is used for signing and sending transactions. | |
| 69 | +
|
| 70 | +### Read-only mode |
| 71 | +
|
| 72 | +The SDK client will be in read-only mode if any of the following conditions are true: |
| 73 | +
|
| 74 | +- The client was initialized without a wallet client. |
| 75 | +- The client was initialized with a wallet client connected to a chain that is not supported in the environment. |
| 76 | +
|
| 77 | +### Logging |
| 78 | +
|
| 79 | +The logger for the SDK uses the log level based on the value of the LOG_LEVEL environment variable. The log level |
| 80 | +determines which log messages are printed to the console. By default, the logger is configured to log messages with a |
| 81 | +level of info or higher to the console. |
| 82 | +
|
| 83 | +## Modules |
| 84 | +
|
| 85 | +### Storage |
| 86 | +
|
| 87 | +The `storage` module is an utility service for easy access to the hypercerts API. It's built based on the OpenAPI spec |
| 88 | +exposed by the hypercerts API. |
| 89 | +
|
| 90 | +```js |
| 91 | + const client = new HypercertClient({ |
| 92 | + environment: "test", |
| 93 | + walletClient, // optional, client will default to read-only mode if not provided |
| 94 | + publicClient, // optional, can be infered from walletClient if present |
| 95 | +}); |
| 96 | + |
| 97 | +const storage = client.storage; |
| 98 | + |
| 99 | +const storageRequest = { metadata: {...}} |
| 100 | +const storageResponse = await client.storage.storeMetadata(storageRequest); |
| 101 | +``` |
0 commit comments