Skip to content

Commit 5e14122

Browse files
bgodlinjamesbayly
andauthored
Add Dymension Quickstart (#459)
* Option Enabled; NEAR and EVM rationalised * `snippets` folder moved * Cosmos snippets * Dymension Example Featured * Snippets Renamed * Update from Merge * Remove Mapping Near --------- Co-authored-by: James Bayly <[email protected]>
1 parent 226349c commit 5e14122

File tree

5 files changed

+179
-12
lines changed

5 files changed

+179
-12
lines changed

docs/.vuepress/sidebar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ export const getSidebar = (locale: string) =>
237237
text: "Cronos (EVM)",
238238
link: `${locale}/quickstart/quickstart_chains/cosmos-cronos.md`,
239239
},
240+
{
241+
text: "Dymension",
242+
link: `${locale}/quickstart/quickstart_chains/cosmos-dymension.md`,
243+
},
240244
{
241245
text: "Juno",
242246
link: `${locale}/quickstart/quickstart_chains/cosmos-juno.md`,
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Dymension Quick Start
2+
3+
Dymension works like a big web system. Users use RollApps (front-end), the Dymension Hub (back-end) manages everything, and data networks (database) store information. RollApps are like interactive apps in Dymension.
4+
5+
The goal of this quick start guide is to index all transfer events and messages on the [Dymension network](https://dymension.network/).
6+
7+
<!-- @include: ../snippets/cosmos-quickstart-reference.md -->
8+
9+
::: tip
10+
The final code of this project can be found [here](https://github.com/subquery/cosmos-subql-starter/tree/main/Dymension/dymension-starter).
11+
:::
12+
13+
<!-- @include: ../snippets/cosmos-manifest-intro.md -->
14+
15+
::: code-tabs
16+
17+
@tab `project.ts`
18+
19+
```ts
20+
dataSources: [
21+
{
22+
kind: CosmosDatasourceKind.Runtime,
23+
startBlock: 1326903,
24+
mapping: {
25+
file: "./dist/index.js",
26+
handlers: [
27+
{
28+
handler: "handleEvent",
29+
kind: CosmosHandlerKind.Event,
30+
filter: {
31+
type: "transfer",
32+
messageFilter: {
33+
type: "/cosmos.bank.v1beta1.MsgSend",
34+
},
35+
},
36+
},
37+
],
38+
},
39+
},
40+
];
41+
```
42+
43+
:::
44+
45+
Here we are in search of a single type of – namely, `transfer` representing the transfers.
46+
47+
<!-- @include: ../snippets/cosmos-manifest-note.md -->
48+
49+
<!-- @include: ../snippets/schema-intro.md -->
50+
51+
```graphql
52+
type Transfer @entity {
53+
id: ID!
54+
blockHeight: BigInt
55+
txHash: String
56+
fromAddress: String
57+
toAddress: String
58+
amount: String
59+
}
60+
```
61+
62+
The single enity is the `Transfer`.
63+
64+
<!-- @include: ../snippets/cosmos-codegen.md -->
65+
66+
<!-- @include: ../snippets/cosmos-mapping-intro.md -->
67+
68+
::: code-tabs
69+
@tab:active `mappingHandlers.ts`
70+
71+
```ts
72+
import { Transfer } from "../types";
73+
import { CosmosEvent } from "@subql/types-cosmos";
74+
75+
export async function handleEvent(event: CosmosEvent): Promise<void> {
76+
const eventRecord = Transfer.create({
77+
id: `${event.tx.hash}-${event.msg.idx}-${event.idx}`,
78+
blockHeight: BigInt(event.block.block.header.height),
79+
txHash: event.tx.hash,
80+
toAddress: "",
81+
amount: "",
82+
fromAddress: "",
83+
});
84+
for (const attr of event.event.attributes) {
85+
switch (attr.key) {
86+
case "recipient":
87+
eventRecord.toAddress = attr.value;
88+
break;
89+
case "amount":
90+
eventRecord.amount = attr.value;
91+
break;
92+
case "sender":
93+
eventRecord.fromAddress = attr.value;
94+
break;
95+
default:
96+
break;
97+
}
98+
}
99+
await eventRecord.save();
100+
}
101+
```
102+
103+
:::
104+
105+
In the Dymension SubQuery project, we have two a single function, namely `handleEvent`. The `handleEvent` function is also triggered when a `/cosmos.bank.v1beta1.MsgSend` type message is detected for a transfer. It receives an event of type `CosmosEvent`, and then it also extracts blockHeight, transaction hash, from, to and amount from the `event` object.
106+
107+
<!-- @include: ../snippets/cosmos-mapping-note.md -->
108+
109+
::: tip
110+
The final code of this project can be found [here](https://github.com/subquery/cosmos-subql-starter/tree/main/Dymension/dymension-starter).
111+
:::
112+
113+
<!-- @include: ../snippets/build.md -->
114+
115+
<!-- @include: ../snippets/run-locally.md -->
116+
117+
<!-- @include: ../snippets/query-intro.md -->
118+
119+
#### Request
120+
121+
```graphql
122+
{
123+
query {
124+
transfers(first: 5) {
125+
nodes {
126+
id
127+
blockHeight
128+
txHash
129+
recipient
130+
sender
131+
amount
132+
}
133+
}
134+
}
135+
}
136+
```
137+
138+
#### Response
139+
140+
```json
141+
{
142+
"data": {
143+
"query": {
144+
"transfers": {
145+
"nodes": [
146+
{
147+
"id": "56C9A9D33C8C222A25D16AFF1C032561703F765D3DB1DD2B217B07DDB394A24C-0-0",
148+
"blockHeight": "1651519",
149+
"txHash": "56C9A9D33C8C222A25D16AFF1C032561703F765D3DB1DD2B217B07DDB394A24C",
150+
"fromAddress": "dym1g8sf7w4cz5gtupa6y62h3q6a4gjv37pgefnpt5",
151+
"toAddress": "dym1a4gqlkq2qu8fnncxfv9wdt67zthcfyqwx92g0g",
152+
"amount": "200000000000000000000udym"
153+
}
154+
]
155+
}
156+
}
157+
}
158+
}
159+
```
160+
161+
<!-- @include: ../snippets/whats-next.md -->
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<!-- #region level2 -->
22

3-
<!-- @include: ./manifest-intro.md#level2 -->
3+
<!-- @include: ../../snippets/manifest-intro.md#level2 -->
44

55
The Multichain project contains multiple manifest files, with support for the following handlers:
66

7-
<!-- @include: ./evm-handlers.md -->
7+
<!-- @include: ../../snippets/evm-handlers.md -->
88

99
<!-- #endregion level2 -->
1010

1111
<!-- #region level3 -->
1212

13-
<!-- @include: ./manifest-intro.md#level3 -->
13+
<!-- @include: ../../snippets/manifest-intro.md#level3 -->
1414

1515
The Multichain project contains multiple manifest files, with support for the following handlers:
1616

17-
<!-- @include: ./evm-handlers.md -->
17+
<!-- @include: ../../snippets/evm-handlers.md -->
1818

1919
<!-- #endregion level3 -->
2020

2121
<!-- #region level4 -->
2222

23-
<!-- @include: ./manifest-intro.md#level4 -->
23+
<!-- @include: ../../snippets/manifest-intro.md#level4 -->
2424

2525
The Multichain project contains multiple manifest files, with support for the following handlers:
2626

27-
<!-- @include: ./evm-handlers.md -->
27+
<!-- @include: ../../snippets/evm-handlers.md -->
2828

2929
<!-- #endregion level4 -->
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<!-- #region level2 -->
22

3-
<!-- @include: ./manifest-intro.md#level2 -->
3+
<!-- @include: ../../snippets/manifest-intro.md#level2 -->
44

55
The Multichain project contains multiple manifest files, with support for the following handlers:
66

7-
<!-- @include: ./evm-handlers.md -->
7+
<!-- @include: ../../snippets/evm-handlers.md -->
88

99
<!-- #endregion level2 -->
1010

1111
<!-- #region level3 -->
1212

13-
<!-- @include: ./manifest-intro.md#level3 -->
13+
<!-- @include: ../../snippets/manifest-intro.md#level3 -->
1414

1515
The Multichain project contains multiple manifest files, with support for the following handlers:
1616

17-
<!-- @include: ./evm-handlers.md -->
17+
<!-- @include: ../../snippets/evm-handlers.md -->
1818

1919
<!-- #endregion level3 -->
2020

2121
<!-- #region level4 -->
2222

23-
<!-- @include: ./manifest-intro.md#level4 -->
23+
<!-- @include: ../../snippets/manifest-intro.md#level4 -->
2424

2525
The Multichain project contains multiple manifest files, with support for the following handlers:
2626

27-
<!-- @include: ./evm-handlers.md -->
27+
<!-- @include: ../../snippets/evm-handlers.md -->
2828

2929
<!-- #endregion level4 -->
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
::: info
2+
23
This network is based on the Cosmos SDK, which means you can index chain data via the standard Cosmos RPC interface.
34

45
Before we begin, make sure that you have initialised your project using the provided steps in the **[Start Here](../quickstart.md)** section. You must complete the suggested [4 steps](https://github.com/subquery/cosmos-subql-starter#readme) for Cosmos users.
6+
57
:::

0 commit comments

Comments
 (0)