forked from MetaMask/web3-provider-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
23 lines (20 loc) · 769 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const Ethjs = require('ethjs')
const ProviderEngine = require('./index.js')
const ZeroClientProvider = require('./zero.js')
// create engine
const providerEngine = ZeroClientProvider({
// supports http and websockets
// but defaults to infura's mainnet rest api
// rpcUrl: 'https://mainnet.infura.io',
// rpcUrl: 'http://localhost:8545',
// rpcUrl: 'wss://mainnet.infura.io/ws',
// rpcUrl: 'ws://localhost:8545/ws',
})
// use the provider to instantiate Ethjs, Web3, etc
const eth = new Ethjs(providerEngine)
// log new blocks
providerEngine.on('block', function(block) {
const blockNumber = Number.parseInt(block.number.toString('hex'), 16)
const blockHash = `0x${block.hash.toString('hex')}`
console.log(`block: #${blockNumber} ${blockHash}`)
})