Business / Sales
⚡ Test Our Private Nodes of 40+ Blockchains just for $50!
How to connect to GetBlock with Web3js
In this guide, we will show you how to get started with web3.js to connect to GetBlock. First of all, you will need to add web3.js library to your project. This can be done using the following commands:
After that you need to create a web3 instance and set a provider.
// In case you are using Node.js
const Web3 = require('web3');
// Setting getblock node as HTTP provider
const provider = new Web3.providers.HttpProvider("https://eth.getblock.io/mainnet/?api_key=YOUR_API_KEY_HERE");
// or as WebSocket provider
const provider = new Web3.providers.WebsocketProvider("wss://eth.getblock.io/mainnet/?api_key=YOUR_API_KEY_HERE");
// Creating web3 instance with given provider
const web3 = new Web3(provider);
// Initializing web3.eth method
var block = web3.eth.getBlockNumber().then(console.log);
All API references can be found in the project documentation at https://web3js.readthedocs.io.