Skip to content

Commit 0d7c990

Browse files
authored
Merge pull request #36 from maticnetwork/link-to-new-doc
Pointing to new doc
2 parents 92bbc90 + 845a24b commit 0d7c990

File tree

1 file changed

+2
-334
lines changed

1 file changed

+2
-334
lines changed

README.md

Lines changed: 2 additions & 334 deletions
Original file line numberDiff line numberDiff line change
@@ -4,346 +4,14 @@
44

55
Dagger is the library for dagger project written for node.js and browser. It uses dagger server to get realtime updates from Ethereum and Matic Network.
66

7-
**About dagger**
7+
## Usage
88

9-
Dagger helps users to develop faster and better Ethereum DApps. For more information:
10-
11-
- [Installation](#install)
12-
- [Example](#example)
13-
- [Network](#network)
14-
- [Events](#events)
15-
- [API](#api)
16-
- [Examples](#examples)
17-
- [Support](#support)
18-
- [License](#license)
19-
20-
<a name="install"></a>
21-
22-
## Installation
23-
24-
#### NPM
25-
---
26-
```sh
27-
# Using Yarn
28-
yarn add @maticnetwork/dagger
29-
30-
# Using NPM
31-
npm install @maticnetwork/dagger --save
32-
```
33-
34-
#### Direct `<script>` Include
35-
---
36-
37-
Simply download `lib/dagger.min.js` and include with a script tag. `Dagger` will be registered as a global variable.
38-
39-
Usage:
40-
```js
41-
var Dagger = window.Dagger
42-
```
43-
44-
<a name="network"></a>
45-
46-
## Networks
47-
48-
### Ethereum
49-
50-
#### Mainnet
51-
52-
```
53-
Websocket: wss://mainnet.dagger.matic.network
54-
Socket: mqtts://mainnet.dagger.matic.network (You can also use `ssl://` protocol)
55-
```
56-
57-
#### Kovan
58-
59-
```
60-
Websocket: wss://kovan.dagger.matic.network
61-
Socket: mqtts://kovan.dagger.matic.network (You can also use `ssl://` protocol)
62-
```
63-
64-
#### Ropsten
65-
66-
```
67-
Websocket: wss://ropsten.dagger.matic.network
68-
Socket: mqtts://ropsten.dagger.matic.network (You can also use `ssl://` protocol)
69-
```
70-
71-
#### Goerli
72-
73-
```
74-
Websocket: wss://goerli.dagger.matic.network
75-
Socket: mqtts://goerli.dagger.matic.network (You can also use `ssl://` protocol)
76-
```
77-
78-
### Matic
79-
80-
#### Matic mainnet
81-
82-
```
83-
Websocket: wss://matic-mainnet.dagger.matic.network
84-
Socket: mqtts://matic-mainnet.dagger.matic.network (You can also use `ssl://` protocol)
85-
```
86-
87-
#### Matic Mumbai Testnet
88-
89-
```
90-
Websocket: wss://mumbai-dagger.matic.today
91-
Socket: mqtts://mumbai-dagger.matic.today (You can also use `ssl://` protocol)
92-
```
93-
94-
<a name="example"></a>
95-
96-
## Example
97-
98-
```javascript
99-
var Dagger = require(" @maticnetwork/dagger");
100-
101-
// connect to Dagger ETH main network (network id: 1) over web socket
102-
var dagger = new Dagger("wss://mainnet.dagger.matic.network"); // dagger server
103-
104-
// Use mqtt protocol for node (socket)
105-
// var dagger = new Dagger('mqtts://mainnet.dagger.matic.network'); // dagger server
106-
107-
// get new block as soon as it gets created
108-
dagger.on("latest:block", function(result) {
109-
console.log("New block created: ", result);
110-
});
111-
112-
// get only block number (as it gets created)
113-
dagger.on("latest:block.number", function(result) {
114-
console.log("Current block number: ", result);
115-
});
116-
```
117-
118-
**Test dagger server**
119-
120-
This library consists `woodendagger` executable which is test dagger server on your local machine. So you can test with TestRPC.
121-
122-
Please do not use `woodendagger` in production. It's only for development purpose. It doesn't support `removed` flag.
123-
124-
```bash
125-
$ woodendagger --url=https://mainnet.infura.io # or http://localhost:8545 for local json-rpc
126-
127-
# If you want to start dagger server on different ports,
128-
# sockport: socket port for backend connection over TCP
129-
# wsport: websocket port for frontend connection over websocket
130-
$ woodendagger --url=http://localhost:8545 --sockport=1883 --wsport=1884
131-
132-
# To connect from dagger:
133-
var dagger = new Dagger('mqtt://localhost:1883')
134-
```
135-
136-
<a name="events"></a>
137-
138-
## Events
139-
140-
**Ethereum events**
141-
142-
Every ethereum event has room, and there are two rooms: `latest` and `confirmed`. `latest` events are fired immediately block included in chain. `confirmed` events are fired after 12 confirmations.
143-
144-
If you want to show updates on UI in your DApp, use `latest` events. It will help to make UI/UX better and user friendly.
145-
146-
Use `confirmed` events for irreversible tasks from server or on UI. Like sending email, notifications or allow user to do subsequent task on UI after one transaction gets confirmed.
147-
148-
Every event has to start with room:
149-
150-
```javascript
151-
// latest block number
152-
dagger.on("latest:block.number", function(result) {
153-
console.log("Current block number: ", result.data);
154-
});
155-
156-
// confirmed (irreversible) incoming transaction
157-
dagger.on("confirmed:addr/0xa7447.../tx/in", function(result) {
158-
// send email to user about new transaction she received
159-
});
160-
161-
// confirmed (irreversible) contract deployment
162-
dagger.on("confirmed:tx/0xd66169d..../receipt", function(result) {
163-
// send notification to user saying - her contract has been deployed successfully
164-
});
165-
```
166-
167-
You can use wildcard for events too. There are two type of wildcards: `+` (for single) and `#` (for multiple). Use with caution as it will fetch more data then you need, and can bombard with data to your DApp.
168-
169-
```javascript
170-
// Listen for every outgoing transaction for any address
171-
dagger.on('latest:addr/+/tx/out', ...)
172-
173-
// Triggers when 1 GNT (Golem token) get transferred to Golem multisig wallet
174-
dagger.on('latest:log/0xa74476443119a942de498590fe1f2454d7d4ac0d/filter/0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef/+/0x7da82c7ab4771ff031b66538d2fb9b0b047f6cf9/#', ...)
175-
176-
// Triggers when any amount of GNT (Golem token) get sent from Golem multisig wallet
177-
dagger.on('latest:log/0xa74476443119a942de498590fe1f2454d7d4ac0d/filter/0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef/0x7da82c7ab4771ff031b66538d2fb9b0b047f6cf9/#', ...)
178-
179-
// Listen for every Golem token transfer (notice `#` at the end)
180-
dagger.on('latest:log/0xa74476443119a942de498590fe1f2454d7d4ac0d/filter/0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef/#', ...)
181-
```
182-
183-
| Ethereum event | When? | `removed` flag |
184-
| ---------------------------------------------- | ----------------------------------------------------------------------- | -------------- |
185-
| block.number | For every new block number created | |
186-
| block.hash | For every new block hash created | Yes |
187-
| block | For every new block created | Yes |
188-
| block/`number` | When particular block in future included in chain | Yes |
189-
| addr/`address`/tx | On every new transaction for `address` | Yes |
190-
| addr/`address`/tx/out | On every new outgoing transaction for `address` | Yes |
191-
| addr/`address`/tx/in | On every new incoming transaction for `address` | Yes |
192-
| tx/`txId` | When given `txId` included in block | Yes |
193-
| tx/`txId`/success | When tx status is success (included in block) for `txId` | Yes |
194-
| tx/`txId`/fail | When tx fails (included in block) for `txId` | Yes |
195-
| tx/`txId`/receipt | When receipt is generated (included in block) for `txId` | Yes |
196-
| addr/`contractAddress`/deployed | When new `contractAddress` included in block | Yes |
197-
| log/`contractAddress` | When new log generated for `contractAddress` | Yes |
198-
| log/`contractAddress`/filter/`topic0`/`topic1` | When new log with `topic0` and `topic1` generated for `contractAddress` | Yes |
199-
200-
**Dagger events**
201-
202-
| Dagger event | When? | args |
203-
| ----------------- | ------------------------------ | -------------- |
204-
| connection.status | When connection status changes | value: Boolean |
205-
206-
> Event names are case-sensitive. `address`, `txId` and `topics` must be in lowercase.
207-
208-
<a name="api"></a>
209-
210-
## API
211-
212-
- <a href="#connect"><code>Dagger.<b>connect()</b></code></a>
213-
- <a href="#on"><code>dagger.<b>on()</b></code></a>
214-
- <a href="#once"><code>dagger.<b>once()</b></code></a>
215-
- <a href="#off"><code>dagger.<b>off()</b></code></a>
216-
- <a href="#of"><code>dagger.<b>of()</b></code></a>
217-
- <a href="#end"><code>dagger.<b>end()</b></code></a>
218-
- <a href="#contract"><code>dagger.<b>contract()</b></code></a>
219-
220-
---
221-
222-
<a name="connect"></a>
223-
224-
### Dagger.connect(url, options)
225-
226-
Connects to the dagger specified by the given url and options. It returns a Dagger object.
227-
228-
---
229-
230-
<a name="on"></a>
231-
232-
### dagger.on(event, fn)
233-
234-
Subscribe to a topic
235-
236-
- `event` is a `String` topic to subscribe to. `event` wildcard characters are supported (`+` - for single level and `#` - for multi level)
237-
- `fn` - `function (data, removed)`
238-
fn will be executed when event occurred:
239-
- `data` data from event
240-
- `removed` flag saying if data is removed from blockchain due to re-organization.
241-
242-
---
243-
244-
<a name="once"></a>
245-
246-
### dagger.once(event, fn)
247-
248-
Same as `on` but will be fired only once.
249-
250-
---
251-
252-
<a name="off"></a>
253-
254-
### dagger.off(event, fn)
255-
256-
Unsubscribe from a topic
257-
258-
- `event` is a `String` topic to unsubscribe from
259-
- `fn` - `function (data, removed)`
260-
261-
---
262-
263-
<a name="of"></a>
264-
265-
### dagger.of(room)
266-
267-
Create room out of dagger. `room` has to be one out of two values: `latest` and `confirmed`
268-
269-
- `room` object has following methods:
270-
- `on` same as dagger `on`
271-
- `once` same as dagger `once`
272-
- `off` same as dagger `off`
273-
274-
---
275-
276-
<a name="end"></a>
277-
278-
### dagger.end([force])
279-
280-
Close the dagger, accepts the following options:
281-
282-
- `force`: passing it to true will close the dagger right away. This parameter is optional.
283-
284-
---
285-
286-
<a name="contract"></a>
287-
288-
### dagger.contract(web3Contract)
289-
290-
Creates web3 contract wrapper to support dagger.
291-
292-
- `web3Contract`: contract object web3. Example: `new web3.eth.Contract(abi, address)`
293-
294-
```javascript
295-
// web3 contract
296-
var web3Contract = new web3.eth.Contract(abi, address);
297-
298-
// dagger contract
299-
var contract = dagger.contract(web3Contract);
300-
var filter = contract.events.Transfer({
301-
filter: { from: "0x123456..." },
302-
room: "latest"
303-
});
304-
// watch
305-
filter.watch(function(data, removed) {
306-
// data.returnValues.to : address to which it has been transferred to
307-
// data.returnValues.value : value which has been transferred
308-
});
309-
// watch only once
310-
filter.watchOnce(function(data, removed) {
311-
// data.returnValues.to : address to which it has been transferred to
312-
// data.returnValues.value : value which has been transferred
313-
});
314-
// stop watching
315-
filter.stopWatching();
316-
```
317-
318-
<a name="examples"></a>
319-
320-
## Examples
321-
322-
**To listen ERC20 transfer event**
323-
324-
Use following topic to listen ERC20 transfer event. Use `+` instead of <contract-address> or <from-address> or <to-address> if you want to listen for `any` value.
325-
326-
For latest events:
327-
328-
```
329-
latest:log/<contract-address>/filter/0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef/<from-address>/<to-address>
330-
```
331-
332-
For confirmed events:
333-
334-
```
335-
confirmed:log/<contract-address>/filter/0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef/<from-address>/<to-address>
336-
```
337-
338-
339-
<a name="support"></a>
9+
Follow this documentation [here](https://docs.matic.network/docs/develop/dagger)
34010

34111
## Support
34212

34313
If you have any queries, feedback or feature requests, feel free to reach out to us on telegram: https://t.me/maticnetwork
34414

345-
<a name="license"></a>
346-
34715
## License
34816

34917
MIT

0 commit comments

Comments
 (0)