Web3.js

Using web3.js with POSI Chain protocol.

Introduction

Web3.js is a set of libraries that allow developers to interact with Ethereum nodes using HTTP, IPC or WebSocket protocols. POSI Chain has an Ethereum-like API available that is fully compatible with Ethereum-style JSON RPC invocations. Therefore, developers can leverage this compatibility and use the web3.js library to interact with a POSI Chain node as if they were doing so on Ethereum.

Setup Web3.js with POSI Chain

To get started with the web3.js library, we first need to install it using the following command:

npm install web3

Once done, the simplest setup to start using the library and its methods is the following:

const Web3 = require('web3');

//Create web3 instance
const web3 = new Web3(PSC_RPC_URL);

Depending on which network you want to connect to, you can set the PSC_RPC_URL to the following values:

For Mainnet:

PSC_RPC_URL = https://api.posichain.org

For Testnet:

PSC_RPC_URL = https://api.s0.t.posichain.org

Tutorials

In the case that you are interested in a more detailed step-by-step guide, you can go to our specific tutorials on using web3.js on a POSI Chain:

pageSend transactionpageFind the last transaction

The steps can also be adapted to deploy on the POSI Chain Testnet, by using the correct RPC_URL as mentioned before.

You can use all the library functions described in the official Web3 documentation.

Last updated