Web3.js integration

Learn how to use Web3.js, a widely-used JavaScript library for connecting to GetBlock nodes.

Web3.js is a JavaScript library built for interacting with the Ethereum blockchain and other EVM-compatible chains. It is used to send JSON-RPC calls to the Ethereum node via HTTP, IPC, or WebSocket connection to read data from the blockchain, make transactions, or deploy smart contracts.

Install Web3.js

Use your preferred package manager:

  • npm:

npm install web3
  • yarn:

yarn add web3
  • Pure js link:

dist/web3.min.js

Set up your connection to GetBlock

// Import the Web3 library
const Web3 = require('web3');

// Set GetBlock as the provider (replace ACCESS_TOKEN with your actual token)
var web3 = new Web3('https://go.getblock.io/ACCESS_TOKEN');

// Initialize web3 method
web3.eth.getBlockNumber().then(console.log);

For additional methods and options, refer to the official Web3.js documentation.

Last updated

© 2019-2024 GetBlock LLC. All rights reserved ID: 21835790. Address: Belgrade, Serbia.