|
1 | 1 | # @kleros/kleros-sdk
|
2 | 2 |
|
3 |
| -_Archon's successor_ |
| 3 | +**The official TypeScript SDK for interacting with the Kleros V2 protocol.** |
4 | 4 |
|
5 |
| -To run the data mappings tests, at the root folder level, do: |
| 5 | +_This SDK is the successor to Archon and provides developers with a comprehensive set of tools to build applications on top of Kleros._ |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [Features](#features) |
| 10 | +- [Installation](#installation) |
| 11 | +- [Getting Started](#getting-started) |
| 12 | + - [Configuration](#configuration) |
| 13 | + - [Quick Start Example](#quick-start-example) |
| 14 | +- [Core Concepts](#core-concepts) |
| 15 | + - [Public Client](#public-client) |
| 16 | + - [Data Mappings](#data-mappings) |
| 17 | + - [Requests](#requests) |
| 18 | +- [API Documentation](#api-documentation) |
| 19 | +- [Examples](#examples) |
| 20 | +- [Contributing](#contributing) |
| 21 | +- [License](#license) |
| 22 | + |
| 23 | +## Features |
| 24 | + |
| 25 | +* **Viem Integration**: Leverages the power and efficiency of [Viem](httpsa://viem.sh/) for Ethereum blockchain interactions. |
| 26 | +* **Type-Safe**: Fully written in TypeScript for robust type checking and improved developer experience. |
| 27 | +* **Dispute Resolution**: Tools to fetch dispute details, and interact with the Kleros arbitration process. |
| 28 | +* **Data Handling**: Utilities for working with Kleros-specific data structures and evidence. |
| 29 | +* **Subgraph Interaction**: Functionality to query Kleros subgraphs for indexed data. |
| 30 | +* **IPFS Support**: Helpers for fetching data stored on IPFS. |
| 31 | + |
| 32 | +## Installation |
| 33 | + |
| 34 | +You can install the Kleros SDK using npm or yarn: |
6 | 35 |
|
7 | 36 | ```bash
|
| 37 | +# Using npm |
| 38 | +npm install @kleros/kleros-sdk viem |
| 39 | + |
| 40 | +# Using yarn |
| 41 | +yarn add @kleros/kleros-sdk viem |
| 42 | +``` |
| 43 | + |
| 44 | +**Note:** `@kleros/kleros-sdk` has `viem` as a peer dependency, so you need to install it separately in your project. |
| 45 | + |
| 46 | +## Getting Started |
| 47 | + |
| 48 | +### Configuration |
| 49 | + |
| 50 | +Before you can use the SDK, you need to configure it with a `viem` Public Client instance. This client will be used for all blockchain interactions. |
| 51 | + |
| 52 | +```typescript |
| 53 | +import { configureSDK } from '@kleros/kleros-sdk'; |
| 54 | +import { createPublicClient, http } from 'viem'; |
| 55 | +import { mainnet } from 'viem/chains'; // Or your desired chain |
| 56 | + |
| 57 | +// Create a viem public client |
| 58 | +const publicClient = createPublicClient({ |
| 59 | + chain: mainnet, |
| 60 | + transport: http(), // Replace with your preferred transport (e.g., Infura, Alchemy) |
| 61 | +}); |
| 62 | + |
| 63 | +// Configure the Kleros SDK |
| 64 | +configureSDK({ client: publicClient }); |
| 65 | + |
| 66 | +console.log('Kleros SDK configured!'); |
| 67 | +``` |
| 68 | + |
| 69 | +### Quick Start Example |
| 70 | + |
| 71 | +Here's a simple example of how to fetch details for a specific dispute: |
| 72 | + |
| 73 | +```typescript |
| 74 | +import { configureSDK, KlerosSDK } from '@kleros/kleros-sdk'; // Assuming KlerosSDK is the main class or namespace |
| 75 | +import { createPublicClient, http } from 'viem'; |
| 76 | +import { mainnet } from 'viem/chains'; |
| 77 | + |
| 78 | +// Configure the SDK (as shown above) |
| 79 | +const publicClient = createPublicClient({ |
| 80 | + chain: mainnet, |
| 81 | + transport: http(), |
| 82 | +}); |
| 83 | +configureSDK({ client: publicClient }); |
| 84 | + |
| 85 | +// Example: Fetching dispute details (Illustrative - actual API might differ) |
| 86 | +// Replace with actual SDK usage once API is fully explored |
| 87 | +async function getDisputeExample(disputeId: string) { |
| 88 | + try { |
| 89 | + // Placeholder: Actual function to get dispute details needs to be identified |
| 90 | + // For now, we'll assume a function getDisputeDetails exists or similar |
| 91 | + // const disputeDetails = await KlerosSDK.getDisputeDetails(disputeId); |
| 92 | + // console.log('Dispute Details:', disputeDetails); |
| 93 | + |
| 94 | + console.log(`Fetching details for dispute ${disputeId}... (Illustrative)`); |
| 95 | + // This part will be updated once the actual API for fetching disputes is clear. |
| 96 | + // For now, we refer to functions that might exist based on file names like 'getDispute.ts' or 'fetchDisputeDetails.ts' |
| 97 | + // For example, if 'getDispute' is the correct function: |
| 98 | + // import { getDispute } from '@kleros/kleros-sdk'; |
| 99 | + // const dispute = await getDispute(disputeId, publicClient); // publicClient might be implicitly used or passed |
| 100 | + // console.log(dispute); |
| 101 | + |
| 102 | + |
| 103 | + } catch (error) { |
| 104 | + console.error('Error fetching dispute details:', error); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +getDisputeExample('123'); // Replace '123' with an actual dispute ID |
| 109 | +``` |
| 110 | +*Note: The Quick Start example is illustrative. The exact API usage, especially for fetching dispute details, will be refined as the SDK's public API is further clarified in subsequent steps.* |
| 111 | + |
| 112 | +## Core Concepts |
| 113 | + |
| 114 | +### Public Client |
| 115 | + |
| 116 | +The SDK uses a `viem` Public Client for all on-chain interactions. You must provide this client during the SDK's configuration. This design gives you full control over the Ethereum connection (e.g., choice of RPC provider, chain). |
| 117 | + |
| 118 | +### Data Mappings |
| 119 | + |
| 120 | +The `dataMappings` module (found in `src/dataMappings`) is a powerful feature that allows for complex data retrieval and processing. It can execute a series of actions, such as: |
| 121 | +* Calling smart contract functions |
| 122 | +* Fetching JSON data from IPFS |
| 123 | +* Querying Kleros subgraphs |
| 124 | +It uses a template-based system to populate data structures based on the results of these actions. This is particularly useful for constructing the `metaEvidence` and `evidence` associated with disputes. |
| 125 | + |
| 126 | +### Requests |
| 127 | + |
| 128 | +The `requests` module (found in `src/requests`) provides functions for making specific queries, often to Kleros subgraphs via GraphQL. For example, `fetchDisputeDetails.ts` likely uses this module to retrieve detailed information about a dispute. |
| 129 | + |
| 130 | +## API Documentation |
| 131 | + |
| 132 | +Detailed API documentation will be generated from TSDoc comments and made available separately. (This will be addressed in Step 2 of the improvement plan). |
| 133 | + |
| 134 | +For now, developers can explore the exported functions and types directly within their IDEs, leveraging TypeScript's autocompletion features. |
| 135 | + |
| 136 | +## Examples |
| 137 | + |
| 138 | +Additional runnable examples demonstrating various SDK features will be added to the `examples/` directory within this package. (This will be addressed in a later step of the improvement plan). |
| 139 | + |
| 140 | +## Contributing |
| 141 | + |
| 142 | +Contributions are welcome! If you find a bug, have a feature request, or want to contribute to the codebase, please: |
| 143 | + |
| 144 | +1. Check the [issue tracker](https://github.com/kleros/kleros-v2/issues) for existing issues. |
| 145 | +2. Open a new issue if yours isn't listed. |
| 146 | +3. For code contributions, please fork the repository and submit a pull request to the `master` (or relevant development) branch. |
| 147 | + |
| 148 | +We use ESLint for linting and Prettier for formatting. Please ensure your contributions adhere to these standards. |
| 149 | + |
| 150 | +### Running Tests |
| 151 | + |
| 152 | +To run the test suite (powered by Vitest): |
| 153 | + |
| 154 | +```bash |
| 155 | +# From the root of the kleros-v2 monorepo |
| 156 | +yarn test packages/kleros-sdk |
| 157 | + |
| 158 | +# Or, if you are inside the kleros-sdk package directory |
8 | 159 | yarn test
|
9 | 160 | ```
|
10 | 161 |
|
11 |
| -🚧 ⚖️ 🚧 |
| 162 | +## License |
| 163 | + |
| 164 | +This SDK is licensed under the [MIT License](./LICENSE). |
0 commit comments