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
An ethereum smart contract event cache. Query your smart contract events in ways that you can't do directly on the blockchain. A helpful development tool or a helpful addition to your production Dapp.
10
10
11
11
There are three components that dAche uses to track events:
12
12
13
-
-__Rebase__ starts from the block the contract was created and imports events from then until the block that the dAche was started at. This is disabled by default since the included contract has a lot of events !
14
-
-__Watch__ listens live for events on the contracts and immediately pulls them in
15
-
-__Scan__ runs at a defined offset from the newest block on chain, and re-imports events from this range. This is to compensate for any missed live events, which can happen.
13
+
-**Rebase** starts from the block the contract was created and imports events from then until the block that the dAche was started at. This is disabled by default since the included contract has a lot of events !
14
+
-**Watch** listens live for events on the contracts and immediately pulls them in
15
+
-**Scan** runs at a defined offset from the newest block on chain, and re-imports events from this range. This is to compensate for any missed live events, which can happen.
16
16
17
17
## Setup
18
18
@@ -21,64 +21,60 @@ First copy `config/default.example.json` and rename to `default.json`.
21
21
By default, dAche will run with an in-memory database (NeDB) to get you up and running quick.
22
22
23
23
Postgres is also supported, so if you prefer that fill out the storage section of the config file with your database info:
24
-
```
25
-
"storage": {
26
-
"type": "postgres",
27
-
"database": "mydb",
28
-
"host": "mydb.db.com",
29
-
"password": "password",
30
-
"user": "admin",
31
-
"port": 5432
32
-
}
33
-
```
24
+
25
+
"storage": {
26
+
"type": "postgres",
27
+
"database": "mydb",
28
+
"host": "mydb.db.com",
29
+
"password": "password",
30
+
"user": "admin",
31
+
"port": 5432
32
+
}
34
33
35
34
To start dAche, `npm install` then `npm start`.
36
35
37
36
## Example 1: Querying CryptoKittiesCore
38
37
39
38
There is a simple GraphQL layer for the dAche API implemented.
40
39
41
-
Visit http://localhost:4000/graphql to view the built-in GrapgQL query interface.
40
+
Visit <http://localhost:4000/graphql> to view the built-in GrapgQL query interface.
42
41
43
42
To see the latest events (ordered by newest blocks by default (order: -1):
44
-
```
45
-
{
46
-
events {
47
-
items {
48
-
contractName
49
-
eventName
50
-
blockNumber
51
-
returnValues
43
+
44
+
{
45
+
events {
46
+
items {
47
+
contractName
48
+
eventName
49
+
blockNumber
50
+
returnValues
51
+
}
52
+
}
52
53
}
53
-
}
54
-
}
55
-
```
56
54
57
55
We have implemented example queries to show how you can query the events in a way you can't directly on the blockchain.
58
56
To query all events by a given return value key/value:
59
-
```
60
-
{
61
-
events (
62
-
returnValuesKey: "kittyId",
63
-
returnValuesValue: "5436") {
64
-
items {
65
-
contractName
66
-
eventName
67
-
blockNumber
68
-
returnValues
57
+
58
+
{
59
+
events (
60
+
returnValuesKey: "kittyId",
61
+
returnValuesValue: "5436") {
62
+
items {
63
+
contractName
64
+
eventName
65
+
blockNumber
66
+
returnValues
67
+
}
68
+
}
69
69
}
70
-
}
71
-
}
72
-
```
73
70
74
71
## Example 2: Generating a token holder balances report
75
72
76
73
This is an example of a non-grapql use of the Dache. This is a GET endpoint that will return all current token holders of a token contract (a csv of address, balance). We have included the XYO Token contract as an example.
77
74
78
75
Stop the dAche. Update the contractSource.contracts, replace CryptoKittiesCore with XYO. Change rebase.enabled to true. Start the dAche.
79
76
80
-
Visit http://localhost:4000/balances/XYO and
81
-
77
+
Visit <http://localhost:4000/balances/XYO> and
82
78
83
79
## Historic Events (Rebase)
84
80
@@ -91,46 +87,44 @@ Would not recommend enabling this for the CryptoKittiesCore contract unless you
91
87
## Other options
92
88
93
89
Options for `ethereum.network`:
94
-
- mainnet
95
-
- ropsten
96
-
- rinkeby
97
-
- kovan
90
+
91
+
- mainnet
92
+
- ropsten
93
+
- rinkeby
94
+
- kovan
98
95
99
96
To us IPFS to load contracts, update the config to have the following entries:
To use S3 to load contracts instead of a local directory, update the config to have the following entries:
111
-
```
112
-
"aws": {
113
-
"accessKeyId": "123",
114
-
"secretAccessKey": "456",
115
-
"region": "us-east-1"
116
-
},
117
-
"contractSource": {
118
-
"type": "s3",
119
-
"bucketName": "mybucket",
120
-
"keyPrefix": "abi/mainnet/"
121
-
}
122
-
```
107
+
108
+
"aws": {
109
+
"accessKeyId": "123",
110
+
"secretAccessKey": "456",
111
+
"region": "us-east-1"
112
+
},
113
+
"contractSource": {
114
+
"type": "s3",
115
+
"bucketName": "mybucket",
116
+
"keyPrefix": "abi/mainnet/"
117
+
}
123
118
124
119
To only load specific contract(s) from a source, include the "contracts" key as noted below
125
-
```
126
-
"contractSource": {
127
-
"type": "local",
128
-
"directory": "./examples/contracts",
129
-
"contracts": [
130
-
"CryptoKittiesCore"
131
-
]
132
-
}
133
-
```
120
+
121
+
"contractSource": {
122
+
"type": "local",
123
+
"directory": "./examples/contracts",
124
+
"contracts": [
125
+
"CryptoKittiesCore"
126
+
]
127
+
}
134
128
135
129
For the Scan component, you can adjust `sync.blockScanOffset`. This is how many blocks you want to wait before reimporting events that were picked up live.
136
130
@@ -141,4 +135,3 @@ See the [LICENSE.md](LICENSE) file for license details.
141
135
## Credits
142
136
143
137
Made with 🔥and ❄️ by [XY - The Persistent Company](https://www.xy.company)
0 commit comments