Skip to content

Commit 8c21bab

Browse files
authored
Merge pull request #52 from ssvlabs/sdk-and-subgraph-fixes
New SDK initialization
2 parents 2ba4e23 + e758714 commit 8c21bab

File tree

12 files changed

+299
-203
lines changed

12 files changed

+299
-203
lines changed

docs/based-applications/developers/BA-SDK/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ npm i @ssv-labs/bapps-sdk
3939

4040
## Example Usage
4141

42+
The `extendedConfig` parameter in th `BasedAppsSDK` constructor is optional, if not provided, the SDK will use the development endpoint. Bear in mind that this is rate limited, though, so it is strongly advised to use an API key with the free plan.
43+
For more information regarding your subgraph API key, please refer to the [dedicated Subgraph page](../subgraph.md#based-application-subgraph).
44+
4245
```typescript
4346
import { BasedAppsSDK } from "@ssv-labs/bapps-sdk";
4447
import { createPublicClient, createWalletClient, http } from 'viem'
@@ -64,6 +67,11 @@ const sdk = new BasedAppsSDK({
6467
beaconchainUrl: 'https://example.com/beacon',
6568
publicClient,
6669
walletClient,
70+
extendedConfig: {
71+
subgraph: {
72+
apiKey: "<YOUR_SUBGRAPH_API_KEY>"
73+
}
74+
}
6775
})
6876

6977
async function main(): Promise<void> {

docs/based-applications/developers/smart-contracts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ This smart contract is under development and as such, it is only deployed on the
2222
#### Hoodi Testnet
2323
| Contract | Address |
2424
|-----------------|-------------------------------------------------------------------------------------------------------------|
25-
| SSVBasedApps | [`0x3F2983b813054Eba76Ae137DfA77836CA8b00ACE`](https://hoodi.etherscan.io/address/0x3F2983b813054Eba76Ae137DfA77836CA8b00ACE) |
25+
| SSVBasedApps | [`0xc7fCFeEc5FB9962bDC2234A7a25dCec739e27f9f`](https://hoodi.etherscan.io/address/0xc7fCFeEc5FB9962bDC2234A7a25dCec739e27f9f) |
2626

2727

2828
#### ABI
2929

3030
<!-- TODO missing ABI -->
31-
* [Testnet](https://github.com/ssvlabs/based-applications/tree/contract-abi/docs/testnet/v1.1.0/abi)
31+
* [Testnet](https://github.com/ssvlabs/based-applications/tree/contract-abi/docs/prod/v0.1.0)

docs/based-applications/developers/subgraph.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,50 @@ sidebar_position: 4
66

77
# Based Application Subgraph
88

9+
The Graph is a decentralized indexing protocol for the Ethereum (and other EVM-compatible) blockchains. It allows to process data produced by smart contracts and apply logic to it, making it easier and faster to query.
10+
11+
The Graph can be used for querying data related to the SSV protocol and develop applications on top of it.
12+
13+
:::info
14+
### New to GraphQL?
15+
16+
Before diving into subgraph queries, get familiar with GraphQL basics: [Learn GraphQL](https://graphql.org/learn/)
17+
:::
18+
19+
A Subgraph that implements the necessary logic to index all the events emitted by the SSV smart contract has been developed, and the code is open source, you can [find it here](https://github.com/ssvlabs/ssv-subgraph).
20+
921
All of the data for a based application is stored in the Based Application Subgraph.
1022

11-
## Querying the Subgraph
23+
## Querying SSV Protocol smart contract data
24+
25+
Currently, only the [Hoodi Testnet](https://thegraph.com/explorer/subgraphs/F4AU5vPCuKfHvnLsusibxJEiTN7ELCoYTvnzg3YHGYbh?view=Query&chain=arbitrum-one) subgraph has Based Applications data, as Based Applications are currently still on testnet phase.
26+
27+
There are a few ways to access smart contract data through The Graph.
28+
29+
### Subgraph Playground user interface
30+
31+
First of all, you can access the Subgraph page on the Graph Explorer, and use it to experiment and prototype queries using the provided Playground.
32+
33+
![Subgraph Playground](/img/subgraph-1.png)
34+
35+
It's possible to access the underlying GraphQL schema, by clicking the _folder icon_ on the right of the playground. This is self-documenting, similarly (and more) to Swagger for a RESTful API, but it's also more powerful, since it will allow you to build queries through simple point-and-click interactions.
36+
37+
Once you are satisfied with the query you built, click on the _Play_ button in the center to launch it and obtain the result.
38+
39+
![Subgraph Playground](/img/subgraph-2.png)
40+
41+
42+
Further documentation about the schema can be accessed by clicking on the _book icon_ on the right of the Playground window.
43+
44+
### Query API
45+
46+
The screenshot below shows the lower section of the _Query_ page.
47+
48+
![Subgraph Playground](/img/subgraph-3.png)
1249

13-
The subgraph can be queried at this API for holesky: `https://api.studio.thegraph.com/query/71118/based-applications-ssv-holesky/version/latest`
50+
It provides instructions on how to query this subgraph programmatically, using the public endpoint and an API-key. You can generate your own API key by visiting the [Subgraph Studio page](https://thegraph.com/studio/apikeys/), and selecting API Keys at the top. The free plan allows 100 thousand queries per month, which should be plenty for your development needs.
1451

15-
**Subgraphs for Hoodi will be available soon.**
52+
Delving deeper into programmatically querying the endpoint: in order do this, you would need to know exactly the query you want to perform, and then perform a `POST` request to the provided endpoint, adding the API key as a header to the request.
1653

1754
## Example Queries
1855

docs/developers/SSV-SDK/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ const walletClient = createWalletClient({
6060
const sdk = new SSVSDK({
6161
publicClient,
6262
walletClient,
63+
extendedConfig: {
64+
subgraph: {
65+
apiKey: "<YOUR_SUBGRAPH_API_KEY>"
66+
}
67+
}
6368
})
6469
```
6570

71+
The `extendedConfig` parameter is optional, if not provided, the SDK will use the development endpoint. Bear in mind that this is rate limited, though, so it is strongly advised to use an API key with the free plan.
72+
For more information regarding your subgraph API key, please refer to the [dedicated Subgraph page](../tools/ssv-subgraph/README.md).
73+
6674
### Initialization Parameters
6775

6876
| Input name | Input type | Optional |

docs/developers/tools/ssv-subgraph/README.md

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,63 +23,31 @@ A series of examples of the most useful queries and the data accessible via the
2323

2424
## Querying SSV Protocol smart contract data
2525

26-
Currently, there are two official Subgraphs deployed, one for [Ethereum Mainnet](https://thegraph.com/explorer/subgraphs/7V45fKPugp9psQjgrGsfif98gWzCyC6ChN7CW98VyQnr?view=Playground\&chain=arbitrum-one)
27-
28-
**Explorer for Hoodi will be available soon.**
26+
Currently, there are two official Subgraphs deployed, one for [Ethereum Mainnet](https://thegraph.com/explorer/subgraphs/7V45fKPugp9psQjgrGsfif98gWzCyC6ChN7CW98VyQnr?view=Playground\&chain=arbitrum-one) and one for the [Hoodi Testnet](https://thegraph.com/explorer/subgraphs/F4AU5vPCuKfHvnLsusibxJEiTN7ELCoYTvnzg3YHGYbh?view=Query&chain=arbitrum-one)
2927

3028
There are a few ways to access SSV smart contract data through The Graph.
3129

3230
### Subgraph Playground user interface
3331

3432
First of all, you can access the Subgraph page on the Graph Explorer, and use it to experiment and prototype queries using the provided Playground.
3533

36-
![Subgraph Playground](/img/subgraph-1.avif)
34+
![Subgraph Playground](/img/subgraph-1.png)
3735

3836
It's possible to access the underlying GraphQL schema, by clicking the _folder icon_ on the right of the playground. This is self-documenting, similarly (and more) to Swagger for a RESTful API, but it's also more powerful, since it will allow you to build queries through simple point-and-click interactions.
3937

4038
Once you are satisfied with the query you built, click on the _Play_ button in the center to launch it and obtain the result.
4139

42-
![Subgraph Playground](/img/subgraph-2.avif)
40+
![Subgraph Playground](/img/subgraph-2.png)
4341

4442

4543
Further documentation about the schema can be accessed by clicking on the _book icon_ on the right of the Playground window.
4644

47-
### Developer API
48-
49-
:::info
50-
The developer API is rate limited and should only be used for infrequent queries that are not data heavy, like a single owner nonce, or the cluster snapshot information for a single cluster.
51-
:::
52-
53-
The developer API is typically not publicly accessed, but it is provided below, to foster development of applications built on the SSV protocol. Here are the Developer endpoints for the two deployed Subgraphs:
54-
55-
#### Developer API for Ethereum Mainnet SSV Subgraph
56-
57-
```
58-
https://api.studio.thegraph.com/query/71118/ssv-network-ethereum/version/latest
59-
```
60-
61-
#### Developer API for Hoodi testnet SSV Subgraph
62-
63-
```
64-
https://api.studio.thegraph.com/query/71118/ssv-network-hoodi/version/latest
65-
```
66-
67-
Despite being rate limited, this endpoint should be sufficient for every development use case.
68-
69-
In order to use it, you would need to know exactly the query you want to perform, and then perform a `POST` request to the provided endpoint.
70-
71-
Furthermore, a simple project aimed at providing an example of how to use the subgraph to substitute the [`ssv-scanner`](/developers/tools/ssv-scanner) tool can be found in this repository: [SSV Scanner Demo Repository](https://github.com/raekwonIII/ssv-scanner-demo)
72-
73-
### Production API
74-
75-
As previously mentioned, the Developer API is accessible to anyone for free, but it's rate limited. As such, it should be used for sporadic, light requests.
76-
77-
For demanding and very frequent requests, you should be using the Production API, for which the data is provided by decentralized indexers, who get rewarded by the protocol tokenomics for providing the service.
45+
### Query API
7846

79-
In order to use this endpoint, head over to the Subgraph's page and click on the _Query_ button.
47+
The screenshot below shows the lower section of the _Query_ page.
8048

81-
![Subgraph Playground](/img/subgraph-3.avif)
49+
![Subgraph Playground](/img/subgraph-3.png)
8250

83-
As you can see, the provided URL requires an API key, follow the documentation in the page, to find out how to create one.
51+
It provides instructions on how to query this subgraph programmatically, using the public endpoint and an API-key. You can generate your own API key by visiting the [Subgraph Studio page](https://thegraph.com/studio/apikeys/), and selecting API Keys at the top. The free plan allows 100 thousand queries per month, which should be plenty for your development needs.
8452

85-
Once you have obtained your API key, you can essentially follow the instructions in the previous section, only substituting the URL in the examples with your new endpoint.
53+
Delving deeper into programmatically querying the endpoint: in order do this, you would need to know exactly the query you want to perform, and then perform a `POST` request to the provided endpoint, adding the API key as a header to the request.

static/img/subgraph-1.avif

-510 KB
Binary file not shown.

static/img/subgraph-1.png

297 KB
Loading

static/img/subgraph-2.avif

-637 KB
Binary file not shown.

static/img/subgraph-2.png

335 KB
Loading

static/img/subgraph-3.avif

-393 KB
Binary file not shown.

0 commit comments

Comments
 (0)