Skip to content

Commit fb497d4

Browse files
committed
Cookbook
1 parent 4a0d858 commit fb497d4

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

website/pages/en/cookbook/_meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export default {
1010
derivedfrom: 'Subgraph Best Practice 2: Manage Arrays with @derivedFrom',
1111
'immutable-entities-bytes-as-ids': 'Subgraph Best Practice 3: Using Immutable Entities and Bytes as IDs',
1212
'avoid-eth-calls': 'Subgraph Best Practice 4: Avoid eth_calls',
13+
'transfer-to-the-graph': '',
1314
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
title: Tranfer to The Graph
3+
---
4+
5+
Learn how to quickly upgrade for your subgraphs from any platform to [The Graph's decentralized network](https://thegraph.com/networks/).
6+
7+
## Benefits of Switching to The Graph
8+
9+
- Use the same subgraph that your apps already use with zero-downtime migration
10+
- Increase reliability from a global network supported by 100+ Indexers
11+
- Receive lightning-fast support for subgraphs 24/7, with an on-call engineering team
12+
13+
## Upgrade Your Subgraph to The Graph in 3 Easy Steps
14+
15+
1. [Set Up Your Studio Environment](/cookbook/transfer-to-the-graph/#1-set-up-your-studio-environment)
16+
2. [Deploy Your Subgraph to Studio](/cookbook/transfer-to-the-graph/#2-deploy-your-subgraph-to-studio)
17+
3. [Publish to The Graph Network](/cookbook/transfer-to-the-graph/#publish-your-subgraph-to-the-graphs-decentralized-network)
18+
19+
## 1. Set Up Your Studio Environment
20+
21+
### Install the Graph CLI⁠
22+
23+
On your local machine, run the following commands:
24+
25+
Using [npm](https://www.npmjs.com/):
26+
27+
```sh
28+
graph init --product subgraph-studio
29+
```
30+
31+
### Create a Subgraph in Subgraph Studio
32+
33+
1. Go to [Subgraph Studio](https://thegraph.com/studio/) and connect your wallet.
34+
2. Click "Create a Subgraph". It is recommended to name the subgraph in Title Case: "Subgraph Name Chain Name".
35+
36+
> Note: After publishing, the subgraph name will be editable but requires signing each time, so name it properly.
37+
38+
For additional information on subgraph creation and the Graph CLI, see [Creating a Subgraph](/developing/creating-a-subgraph).
39+
40+
### Authenticate Your Subgraph
41+
42+
In The Graph CLI, use the auth command seen in Subgraph Studio:
43+
44+
```sh
45+
graph auth --studio <your-auth-code>`
46+
```
47+
48+
## 2. Deploy Your Subgraph to Studio
49+
50+
In The Graph CLI, run the following command:
51+
52+
```sh
53+
graph deploy --studio <slug> --ipfs-hash <your-subgraph-ipfs-hash>`
54+
```
55+
56+
> Note: There is no coding required, simply use the **IPFS provided by your current host**. You’ll be prompted to enter a version. eg. v0.0.1.
57+
58+
## 3. Publish Your Subgraph to The Graph Network
59+
60+
![publish button](https://edgeandnode.notion.site/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fa7d6afae-8784-4b15-a90e-ee8f6ee007ba%2F2f9c4526-123d-4164-8ea8-39959c8babbf%2FUntitled.png?table=block&id=37005371-76b4-4780-b044-040a570e3af6&spaceId=a7d6afae-8784-4b15-a90e-ee8f6ee007ba&width=1420&userId=&cache=v2)
61+
62+
### Query Your Subgraph
63+
64+
> Before you can query your subgraph, Indexers need to begin serving queries on it. In order to streamline this process, you can curate your own subgraph using GRT.
65+
66+
You can start querying any subgraph by sending a GraphQL query into the subgraph’s query URL endpoint, which is located at the top of its Explorer page in Subgraph Studio.
67+
68+
#### Example
69+
70+
[CryptoPunks Ethereum subgraph](https://thegraph.com/explorer/subgraphs/HdVdERFUe8h61vm2fDyycHgxjsde5PbB832NHgJfZNqK) by Messari:
71+
72+
The query URL for this subgraph is:
73+
74+
`https://gateway-arbitrum.network.thegraph.com/api/`**\[api-key]**`/subgraphs/id/HdVdERFUe8h61vm2fDyycgxjsde5PbB832NHgJfZNqK`
75+
76+
Now, you simply need to fill in **your own API Key** to start sending GraphQL queries to this endpoint.
77+
78+
### Getting your own API Key
79+
80+
You can create API Keys in Subgraph Studio under the “API Keys” menu at the top of the page:
81+
82+
![API keys](https://lh7-us.googleusercontent.com/docsz/AD_4nXdz7H8hSRf2XqrU0jN3p3KbmuptHvQJbhRHOJh67nBfwh8RVnhTsCFDGA_JQUFizyMn7psQO0Vgk6Vy7cKYH47OyTq5PqycB0xxLyF4kSPsT7hYdMv2MEzAo433sJT6VlQbUAzgPnSxKI9a5Tn3ShSzaxI?key=fnI6SyFgXU9SZRNX5C5vPQ)
83+
84+
### Sample Query
85+
86+
This query shows the most expensive CryptoPunks sold.
87+
88+
```graphql
89+
{
90+
trades(orderBy: priceETH, orderDirection: desc) {
91+
priceETH
92+
tokenId
93+
}
94+
}
95+
```
96+
97+
Passing this into the query URL returns this result:
98+
99+
```
100+
{
101+
"data": {
102+
"trades": [
103+
{
104+
"priceETH": "124457.067524886018255505",
105+
"tokenId": "9998"
106+
},
107+
{
108+
"priceETH": "8000",
109+
"tokenId": "5822"
110+
},
111+
// ...
112+
```
113+
114+
<aside />
115+
116+
### Sample code
117+
118+
```jsx
119+
const axios = require('axios')
120+
121+
const graphqlQuery = `{
122+
trades(orderBy: priceETH, orderDirection: desc) {
123+
priceETH
124+
tokenId
125+
}
126+
}`
127+
const queryUrl =
128+
'https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/HdVdERFUe8h61vm2fDyycHgxjsde5PbB832NHgJfZNqK'
129+
130+
const graphQLRequest = {
131+
method: 'post',
132+
url: queryUrl,
133+
data: {
134+
query: graphqlQuery,
135+
},
136+
}
137+
138+
// Send the GraphQL query
139+
axios(graphQLRequest)
140+
.then((response) => {
141+
// Handle the response here
142+
const data = response.data.data
143+
console.log(data)
144+
})
145+
.catch((error) => {
146+
// Handle any errors
147+
console.error(error)
148+
})
149+
```
150+
151+
### Monitor Subgraph Status
152+
153+
Once you upgrade, you can access and manage your subgraphs in [Subgraph Studio]() and explore all subgraphs in [The Graph Explorer]().
154+
155+
### Additional resources:
156+
157+
- To explore all the ways you can optimize & customize your subgraph for a better performance, read more about [creating a subgraph here](https://thegraph.com/docs/en/developing/creating-a-subgraph/).
158+
- For more information about querying data from your subgraph, read more [here](https://thegraph.com/docs/en/querying/querying-the-graph/).

0 commit comments

Comments
 (0)