# Connecting to the blockchain

Integrating or building solely on the blockchain doesn't require permission from Public Mint or anybody else. You can connect to the Public Mint blockchain by remotely connecting to it and only takes a few steps.

### Web3.js and other wrappers

Developing blockchain-based applications usually requires work on two domains:

1. Smart contract development: code which gets deployed to the blockchain, written in Solidity in the case of Public Mint (and Ethereum);
2. Web or app development: code deployed on the web as an interface to read and write data from the blockchain/smart contracts.

Even though you can connect your web app directly to a client using JSON-RPC calls, you can use a wrapper to make your life easier when trying to connect the two domains and create a full-fledged interface.

![Example of diagram to illustrate stack](https://2049132048-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlveffYY8TD7YiG25FC%2F-LmuKn2ezCRf_5i52__0%2F-Lmv0Bv3IbUoag1RYekb%2FEthereum%20\(2\).png?alt=media\&token=ef264fc4-0cae-476c-993e-ce511f9b2d12)

Web3.js is a collection of Javascript libraries that allow you to easily perform transactions on the blockchain. This includes read/write data, send money, and even deploy smart contracts!&#x20;

{% hint style="success" %}
We use **Node.js**, **publicmint-web3.js**, and similar Javascript-based libraries throughout this documentation. However, you are free to use any language/wrapper you want.
{% endhint %}

## Getting started

Connecting to the blockchain takes just a few steps:

* [Step 1: Connect to a node](#step-2-connect-to-a-node)
* [Step 2: Test your connection](#step-3-test-your-connection)

## Step 1: Connect to a node

The Public Mint client is based on Hyperledger Besu, and likewise it includes a command line interface and JSON-RPC API for running and monitoring nodes. &#x20;

Our client also supports smart contract deployment and operational tools (such as Remix, web3.js, or MyCrypto). Apart from a [few key differences](https://developers.publicmint.io/blockchain-1/start), the interface should be quite familiar to Ethereum developers.

{% hint style="success" %}
In our examples we'll use publicmint-web3.js, this package is a umbrella class that is building above web3.js one of the most popular Javascript libraries for Ethereum. For installation instructions, go to[ publicmint-web3.js](https://public-mint-community.gitlab.io/publicmint-web3.js/) and [web3.js](https://github.com/ethereum/web3.js/) .
{% endhint %}

Start by installing **publicmint-web3.js**. From the terminal, type:

```bash
$ mkdir myDappProject && cd $_ 
$ npm init .
$ npm install @publicmint/publicmint-web3
$ touch index.js
```

Inside `index.js` start by requiring web3:

```javascript
import PublicMint from 'publicmint-web3';

// For JS es5 use:

const PublicMint = require('publicmint-web3').default;

```

This variable will now allow you to create a connection to a Public Mint node.&#x20;

Next, it's time to connect. Depending on whether your are connecting to our TestNet (blockchain used by Public Mint Sandbox environment) or to our MainNet (Public Mint production environment), you should enter the following:

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

```javascript
const web3 = new PublicMint('testNet'); // or chainId 2019
```

{% endtab %}

{% tab title="MainNet" %}

```javascript
const web3 = new PublicMint(); // default 'mainNet' or chainId 2020
```

{% endtab %}
{% endtabs %}

See more about providers [here](https://gitlab.com/public-mint-community/publicmint-web3.js/-/blob/develop/docs/tutorials/ChooseProviders.md).

This step will create a normal web3 instance excluding modules not working for now ([excluded modules](https://www.npmjs.com/package/@publicmint/publicmint-web3)), and create a new namespace `web3.pm` that contains all contracts and basic features for interface with PublicMint client.&#x20;

Learn more about `.pm` [modules](https://public-mint-community.gitlab.io/publicmint-web3.js/).

You're almost done. Now it's time to test it.

## Step 3 - Test your connection

To make sure everything went smoothly, let's query the blockchain for the latest block:

```javascript
> web3.eth.getBlockNumber()
.then(console.log);

> 3141 // Most recent block number
```

Congratulations! You are connected to the Public Mint blockchain. Read on to go through examples of some of the operations you can perform.
