# Web3.js integration

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:

{% tabs %}
{% tab title="npm" %}

```bash
npm install web3
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn add web3
```

{% endtab %}

{% tab title="Pure js link" %}

```bash
dist/web3.min.js
```

{% endtab %}
{% endtabs %}

### Set up your connection to GetBlock

```javascript
// 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](https://web3js.readthedocs.io/en/v1.10.0/index.html).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.getblock.io/guides/using-web3-libraries/web3.js-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
