You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/0.quickstart.md
+59-41Lines changed: 59 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,72 +10,79 @@ This page will guide you through the steps to get your first selective indexer u
10
10
11
11
Let's create an indexer for the [tzBTC FA1.2 token contract](https://tzkt.io/KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn/operations/). Our goal is to save all token transfers to the database and then calculate some statistics of its holders' activity.
12
12
13
-
`demo_token` demo is discussed in this guide; you can find it in the list of available templates when running `dipdup new` command.
13
+
## Install DipDup
14
14
15
15
A modern Linux/macOS distribution with Python 3.11 installed is required to run DipDup.
16
16
17
-
## Create a new project
18
-
19
-
### Interactively (recommended)
20
-
21
-
You can initialize a hello-world project interactively by choosing configuration options in the terminal. The following command will install DipDup for the current user:
17
+
We have a [convenient installer](https://dipdup.io/install.py) that will install DipDup and all the required dependencies for you. It uses pipx to install DipDup as a CLI application and make it available everywhere for the current user. Run the following command in your terminal:
22
18
23
19
```shell [Terminal]
24
20
curl -Lsf https://dipdup.io/install.py | python3
25
21
```
26
22
27
-
Now, let's create a new project:
23
+
If you don't want to use our installer, create a new project directory you can install DipDup manually. You can use any Python package manager you like, but we recommend [PDM](https://pdm.fming.dev/latest/). Here are some spells to get you started:
28
24
29
25
```shell [Terminal]
30
-
dipdup new
31
-
```
26
+
# pipx
27
+
pipx install dipdup datamodel-code-generator pdm
32
28
33
-
Follow the instructions; the project will be created in the current directory. You can skip reading the rest of this page and slap `dipdup run` instead.
29
+
# PDM
30
+
pdm init --python 3.11
31
+
pdm use .venv
32
+
pdm add "dipdup>=7.0.0rc2,<8"
33
+
$(pdm venv activate)
34
34
35
-
### From scratch
35
+
# Poetry
36
+
poetry init --python ">=3.11,<3.12"
37
+
poetry add "dipdup>=7.0.0rc2,<8"
38
+
poetry shell
36
39
37
-
If you don't want to use our installer, you can install DipDup manually. You can use any Python package manager you like, but we recommend [PDM](https://pdm.fming.dev/latest/).
40
+
# pip + venv
41
+
python -m venv .venv
42
+
. .venv/bin/activate
43
+
echo"dipdup>=7.0.0rc2,<8"> requirements.txt
44
+
pip install -r requirements.txt -e .
45
+
```
46
+
47
+
## Create a project
48
+
49
+
DipDup CLI has a built-in project generator. Run the following command in your terminal:
For educational purposes, we'll create a project from scratch, so choose `[none]` network and `demo_blank` template.
47
56
48
-
# Plain pip
49
-
python -m venv .venv
50
-
. .venv/bin/activate
51
-
pip install dipdup
57
+
::banner{type="note"}
58
+
Want to skip a tutorial? Choose `Tezos` and `demo_token` instead!
59
+
::
52
60
53
-
# or Poetry
54
-
poetry init --python ">=3.11,<3.12"
55
-
poetry add dipdup
56
-
poetry shell
57
-
```
61
+
Follow the instructions; the project will be created in the new directory.
58
62
59
63
## Write a configuration file
60
64
61
-
DipDup configuration is stored in YAML files of a specific format. Create a new file named `dipdup.yaml`in the project root with the following content:
65
+
In the project root, you'll find a file named `dipdup.yaml`. It's the main configuration file of your indexer. We will discuss it in detail in the [Config](1.getting_started/3.config.md) section; for now just replace its content with the following:
62
66
63
67
```yaml [dipdup.yaml]
64
68
{{ #include ../src/demo_token/dipdup.yaml }}
65
69
```
66
70
67
71
## Generate types and stubs
68
72
69
-
Now it's time to generate typeclasses and callback stubs. Run the following command:
73
+
Now it's time to generate typeclasses and callback stubs based on definitions from config. Examples below use `demo_token` as a package name; yours may differ.
74
+
75
+
Run the following command:
70
76
71
77
```shell [Terminal]
72
78
dipdup init
73
79
```
74
80
75
-
DipDup will create a Python package `demo_token`having the following structure:
81
+
DipDup will create a Python package `demo_token`with everything you need to start writing your indexer. Use `package tree` command to see the generated structure:
76
82
77
-
```shell
78
-
demo_token [src/demo_token]
83
+
```shell [Terminal]
84
+
$ dipdup package tree
85
+
demo_token [.]
79
86
├── abi
80
87
├── configs
81
88
│ ├── dipdup.compose.yaml
@@ -108,24 +115,25 @@ demo_token [src/demo_token]
108
115
│ ├── tzbtc/tezos_parameters/mint.py
109
116
│ ├── tzbtc/tezos_parameters/transfer.py
110
117
│ └── tzbtc/tezos_storage.py
111
-
├── py.typed
112
-
├── __init__.py
113
-
└── pyproject.toml
118
+
├── demo_token.py
119
+
└── py.typed
114
120
```
115
121
116
122
That's a lot of files and directories! But don't worry, we will need only `models` and `handlers` sections in this guide.
117
123
118
124
## Define data models
119
125
120
-
Our schema will consist of a single model `Holder` having several fields:
126
+
DipDup supports storing data in SQLite, PostgreSQL and TimescaleDB databases. We use custom ORM based on Tortoise ORM as an abstraction layer.
127
+
128
+
First, you need to define a model class. Our schema will consist of a single model `Holder` with the following fields:
121
129
122
130
-`address` — account address
123
-
-`balance` — in tzBTC
124
-
-`volume` — total transfer/mint amount bypassed
131
+
-`balance` — token amount held by the account
132
+
-`volume` — total amount of transfer/mint calls
125
133
-`tx_count` — number of transfers/mints
126
134
-`last_seen` — time of the last transfer/mint
127
135
128
-
Put the following content in the `models/__init__.py` file:
@@ -153,7 +161,7 @@ Three methods of tzBTC contract can alter token balances — `transfer`, `mint`,
153
161
154
162
And that's all! We can run the indexer now.
155
163
156
-
## Next steps
164
+
## Next steps
157
165
158
166
Run the indexer in-memory:
159
167
@@ -176,4 +184,14 @@ cp .env.default .env
176
184
docker-compose up
177
185
```
178
186
179
-
DipDup will fetch all the historical data and then switch to realtime updates. Your application data has been successfully indexed!
187
+
DipDup will fetch all the historical data and then switch to realtime updates. You can check the progress in the logs.
188
+
189
+
If you use SQLite, run a query to check the data:
190
+
191
+
```bash
192
+
sqlite3 demo_token.sqlite 'SELECT * FROM holder LIMIT 10'
193
+
```
194
+
195
+
If you run a Compose stack, check open`http://127.0.0.1:8080`in your browser to see the Hasura console (exposed port may differ). You can use it to explore the database and build GraphQL queries.
196
+
197
+
Congratulations! You've just created your first DipDup indexer. Proceed to the Getting Started section to learn in-depth about DipDup configuration and features.
Copy file name to clipboardExpand all lines: docs/1.getting-started/1.installation.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,18 +46,19 @@ Then use the snippets below to create a new Python project and add DipDup as a d
46
46
PDM is a very powerful package manager with a lot of features. Also, it can run scripts from pyproject.toml as npm does. It's a good choice for both beginners and advanced users.
47
47
48
48
```shell [Terminal]
49
-
pdm init --python ">=3.10,<3.11"
50
-
pdm add dipdup
51
-
pdm venv activate
49
+
pdm init --python 3.11
50
+
pdm use .venv
51
+
pdm add "dipdup>=7.0.0rc2,<8"
52
+
$(pdm venv activate)
52
53
```
53
54
54
55
#### Poetry
55
56
56
57
Poetry is another popular tool to manage Python projects. It's less stable and often slower than PDM, but it's still a good choice.
57
58
58
59
```shell [Terminal]
59
-
poetry init --python ">=3.10,<3.11"
60
-
poetry add dipdup
60
+
poetry init --python ">=3.11,<3.12"
61
+
poetry add "dipdup>=7.0.0rc2,<8"
61
62
poetry shell
62
63
```
63
64
@@ -68,7 +69,7 @@ Finally, if you prefer to do everything manually, you can use pip. It's the most
|:file_folder:`abi`| Contract ABIs used to generate typeclasses |
17
-
|:file_folder:`configs`| Environment-specific configs to merge with the root one |
18
-
|:file_folder:`deploy`| Dockerfiles, compose files, and default env variables for each environment |
19
-
|:file_folder:`graphql`| Custom GraphQL queries to expose with Hasura engine |
20
-
|:file_folder:`handlers`| User-defined callbacks to process contract data |
21
-
|:file_folder:`hasura`| Arbitrary Hasura metadata to apply during configuration |
22
-
|:file_folder:`hooks`| User-defined callbacks to run manually or by schedule |
23
-
|:file_folder:`models`| DipDup ORM models to store data in the database |
24
-
|:file_folder:`sql`| SQL scripts and queries to run manually or on specific events |
25
-
|:file_folder:`types`| Automatically generated Pydantic dataclasses for contract types |
26
-
|`dipdup.yaml`| Root DipDup config; can be expanded with env-specific files |
27
-
|`pyproject.toml`| Python package metadata (introduced in PEP 518; see [details](https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/)) |
|:file_folder:`abi`| Contract ABIs used to generate typeclasses |
17
+
|:file_folder:`configs`| Environment-specific configs to merge with the root one |
18
+
|:file_folder:`deploy`| Dockerfiles, compose files, and default env variables for each environment |
19
+
|:file_folder:`graphql`| Custom GraphQL queries to expose with Hasura engine |
20
+
|:file_folder:`handlers`| User-defined callbacks to process contract data |
21
+
|:file_folder:`hasura`| Arbitrary Hasura metadata to apply during configuration |
22
+
|:file_folder:`hooks`| User-defined callbacks to run manually or by schedule |
23
+
|:file_folder:`models`| DipDup ORM models to store data in the database |
24
+
|:file_folder:`sql`| SQL scripts and queries to run manually or on specific events |
25
+
|:file_folder:`types`| Automatically generated Pydantic dataclasses for contract types |
26
+
|`dipdup.yaml`| Root DipDup config; can be expanded with env-specific files |
27
+
|`{{ project.package }}.py`| A little helper to let you import the package from the root directory. |
28
+
|`pyproject.toml`| Python package metadata (introduced in PEP 518; see [details](https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/)) |
29
+
|||
29
30
30
31
There are also a bunch files in the root directory: .ignore files, PEP 561 marker, etc. Usually, you won't need to modify them.
0 commit comments