-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
33 lines (25 loc) · 747 Bytes
/
example.js
File metadata and controls
33 lines (25 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const HyperETH = require('./')
const hypercore = require('hypercore')
const got = require('got')
const ram = require('random-access-memory')
const endpoint = 'https://eth.hyperdivision.dk'
const feed = hypercore(ram)
async function httpEth (json) {
const res = await got.post({
url: endpoint,
timeout: 5000,
json,
responseType: 'json'
})
return res.body
}
feed.ready(async function () {
const clone = hypercore(ram, feed.key)
const s1 = feed.replicate(true, { live: true })
const s2 = clone.replicate(false, { live: true })
const client = new HyperETH(s1)
const server = new HyperETH(s2, httpEth)
s1.pipe(s2).pipe(s1)
console.log(await client.blockNumber())
console.log(await client.blockNumber())
})