Skip to content
Request a Demo

TLDR;

Install:

npm install web3data-js

Use:

import Web3Data from 'Web3Data'const w3d = new Web3Data('UAK...')w3d.connect()w3d.on({eventName: 'block'}, data => {  console.log(data)  /*{    "blockchainId": "1c9c969065fcd1cf",    "number": 7549499,    "hash": "0x9d5a5b...",    "parentHash": "0x33b18c...",    "nonce": 2322883515373825000,    "miner": "0x04668ec2f57cc15c381b461b9fedab5d451c8f7f",        ... and much more :)  }*/}})

Enjoy: 🤩


If you haven’t figured it out already Amberdata has one of the most comprehensive all encompassing blockchain + market data APIs in the industry.

That’s all fine and dandy but as most developers know (or should know), one of the three virtues of a programmer is laziness. Thus, we wanted to make the development process a breeze by providing you with a simple npm module to quickly get up and running using Amberdata’s API in your next project.

API Key

Before we continue, let’s grab an API. That way we can follow along and see some action!

Sign in or up at Amberdata.io. Then got to Amberdata.io/pricing and click Get Started under the free tier.

It’s just. That. Simple.

Enough talk. Gimme code.

Node.Js

Install

npm install web3data-js

Init

import Web3Data from 'Web3Data'const w3d = new Web3Data('UAK...')

Connect

w3d.connect(status => console.log(status))

Initializes the websocket connection. status will let you know if this process was successful. At this point, you’re ready to start listening for events.

Listen

w3d.on({eventName: 'block'}, blockData => {  console.log(blockData)  /*{    "blockchainId": "1c9c969065fcd1cf",    "number": 7549499,    "hash": "0x9d5a5b...",    "parentHash": "0x33b18c...",    "nonce": 2322883515373825000,    "miner": "0x04668ec2f57cc15c381b461b9fedab5d451c8f7f",    ... and much more :)   }*/})

This will listen for every new block event and log the blockData. Check out the docs to see what data gets returned.

Browser

Most everything is the same as Node with a few minor differences.
Add the script to your html page. It includes the minified, transpiled source code:

<script src="https://unpkg.com/web3data-js/dist/web3data.min.js"></script>

Those import statements that we all love are not yet supported in browser. So we’re required (pun intended) to change them:

const Web3Data = require('Web3Data')

From here, the code is the same as above. There is a little example in the web3data-js repo where you can see this action!

Conclusion

That was a super brief intro to using web3data-js. We’ll be posting a lot tutorials in the future describing all of its features and use cases.

We love hearing about how people are utilizing our api so feel free to reach out via email or twitter and let us know what you’re working on!

Tag(s):

Amberdata Blog

View All Posts