owned this note
owned this note
Published
Linked with GitHub
---
title: "Amberdata Webinar: Web3data.js"
tags: Amberdata, Webinar, Web3data.js
description: Slides for Amberdata Webinar on Web3data.js
slideOptions:
transition: slide
---
## Amberdata Webinar: Web3data.js
### Tue Sep. 10th 12:00PM E.T.
---
## Welcome!
Taylor ➞ Open Source/Community Developer
---
## Schedule
- Web3data.js: About + Setup
- Geting data via Amberdata's API
- Using Web3data.js as a Web3/Ethers Drop-in Replacement
- Realtime Blockchain data with websockets
- Q & A
---
## What is Amberdata?
- All encomposing Blockchain & Market data API
- Dashboards + Panels
- Blockchain Analytics, Metrics, and Security
---
<div style="display: flex">
<img src="https://i.imgur.com/5tVrEU6.png" style="border:none"></img>
<img style="border:none" src="https://i.imgur.com/jJqQ41V.png"></img>
</div>
<div style="display: flex">
<img style="border:none" src="https://i.imgur.com/2KWk1qm.png"></img>
</div>
---
## The API
- Over 70 endpoints
- Real-time & historical time series Blockchain & Market data
- JSON RPC Compliant methods
[Documentaion ➞](https://docs.amberdata.io/reference)
---
## The API Key
Onboarding is fast!
[Getting Started ➞](https://amberdata.io/onboarding)
---
## Web3data.js: Intro
The open source Javascript SDK that makes it easy for dApp developers to start #BUILDing on top of Amberdata's API.
- Intuitive and Simple
- Free up development time to focus on the core logic
---
## Web3data.js: Setup
It begins how all good Javascript projects do...
```
npm install web3data-js
```
```
import Web3Data from 'web3data-js'
const w3d = new Web3Data('YOUR_API_KEY')
```
---
## Example: Address Information
[Docs ➞](https://docs.amberdata.io/reference#get-account-information)
[Example ➞](https://runkit.com/taylorjdawson/5d76de67b868b6001a574ce5)
---
## Example: Contract Details
[Docs ➞](https://docs.amberdata.io/reference#get-contract-details)
[Example ➞](https://runkit.com/taylorjdawson/web3data-js-example-contract-details)
---
## Example: Address Balance
[Docs ➞](https://docs.amberdata.io/reference#get-current-account-balance)
[Example ➞](https://runkit.com/taylorjdawson/web3data-js-example-get-address-balance)
---
## Web3data: web3.js & ether.js drop-in replacement
- Easy for developers with existing dApps to use
- Migration is smooth and simple
- In most cases, it’s as easy as changing a variable name.
---
### Example: Get transaction
```
// web3.js
web3.eth.getTransaction(txnHash [, callback])
// ethers.js
provider.getTransaction(txnHash)
// web3data.js
web3data.eth.getTransaction(txnHash)
```
---
### Difference in Data
- The status of the transaction — success or fail
- Whether it’s confirmed or not along with the number of confirmations
- The fee associated with the transaction
---
### Going further...
```
web3data.eth.getTransaction(txnHash, {includePrice: true})
```
[Example ➞](https://runkit.com/taylorjdawson/web3data-js-get-transaction)
---
### Example: Get block
```
// web3.js
web3.eth.getBlock(blockHashOrBlockNumber [, q3k;2returnTransactionObjects] [, callback])
// ethers.js
prototype.getBlock(blockHashOrBlockNumber)
// web3data.js
web3data.eth.getBlock(blockHashOrBlockNumber)
```
---
### Going further...
```
web3data.eth.getBlock(blockId, {validationMethod: "full"})
```
[Example ➞](https://runkit.com/taylorjdawson/web3data-js-example-get-block)
---
## What's supported?

[Supported Methods Table ➞](https://gist.github.com/taylorjdawson/b1ac3596b893cd2e6b29bc6ff3a6bd80#file-supported_methods-md)
---
## Websockets!
- intuitive
- simple
- concise
---
## Supported Events
- blocks
- transactions & pending transactions
- token transfers
- functions
- market: trades, orders, bbos, ...
- and more!
---
## JSON RPC
> ... a stateless, light-weight remote procedure call (RPC) protocol.
> [jsonrpc.org](jsonrpc.org)
Used by Geth
---
#### Example Subscription Request
```
{
"jsonrpc": "2.0", // rpc version
"id": 1, // client id
"method": "subscribe", // name of the method to be invoked
"params": [ // 1st param event name, 2nd param are filters
"block",
{
"number": 7452758
}
]
}
```
---
#### Example Subscription Response
```
{
"jsonrpc": "2.0",
"id": 1,
"result": "242d29d5ca..." // the server generated id
}
```
---
#### Example Event Response
```
{
"jsonrpc": "2.0",
"method": "subscription",
"params": {
"result": { // Contains the data
"blockchainId": "1c9c969065fcd1cf",
"number": 7452758,
...
},
"subscription": "242d29d5ca..." // the server generated id
}
}
```
---
## Without Web3data.js
```
const WebSocket = require('ws');
const ws = new WebSocket(
'wss://ws.web3api.io',
{headers: {x-api-key:'YOUR_API_KEY'}});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'subscribe',
params: ['block'],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});
```
---
## With Web3data.js!
```
// init
import Web3Data from 'web3data-js'
const w3d = new Web3Data('UAK...')
```
```
// connect
w3d.connect(status => console.log(status))
```
```
// listen
w3d.on({eventName: 'block'}, blockData => blockData)
```
[Example ➞](https://runkit.com/taylorjdawson/web3data-js-example-websocket)
---
## Example: Address Transactions
[Example ➞](https://runkit.com/taylorjdawson/web3data-js-example-websocket-transaction)
---
## Example: Market data
[Example ➞](https://runkit.com/taylorjdawson/web3data-js-example-websocket-market-data)
There's a demo page!
---
# Q & A Time
---
Thanks for listening!
Slides available [here](https://hackmd.io/@1XqK8hlWRW6FMt8Q5EAXJw/SJ1fpC0SB).
Website: Amberdata.io
Docs: Docs.amberdata.io
Follow us on [Medium](https://medium.com/amberdata) & [Twitter](https://twitter.com/Amberdataio)
---
---