Skip to main content
Version: 1.0

Web3.js

Web3.js is a comprehensive JavaScript library that facilitates the integration of applications with the Ethereum Virtual Machine (EVM), including blockchain networks like Wireshape. It enables developers to perform essential blockchain operations such as signing transactions, executing smart contracts, and handling event responses, making it a key tool in the development of decentralized applications (dApps).

Core Capabilities of Web3.js

Web3.js simplifies the interaction between web applications and the Ethereum ecosystem, offering features that cater to various blockchain development needs:

Transaction Management

  • Robust tools for creating, signing, and sending transactions, including WIRE transfers and smart contract interactions.

  • Facilitates efficient and secure transaction management within the Ethereum ecosystem and EVM-compatible networks.

Smart Contract Interaction

  • Facilitates seamless interaction with smart contracts, allowing for the deployment of new contracts, calling of contract functions, and subscription to contract events.

  • Enhances dApp functionalities and user engagement.

Event Listening

  • Enables applications to listen for and react to specific events emitted by smart contracts in real-time.

  • Crucial for creating responsive and interactive applications on Wireshape.

Setting Up Web3.js

Install Web3.js using npm or yarn in your Node.js environment:

npm install web3

or

yarn add web3

Interacting with the Wireshape Blockchain

To configure your project for Wireshape, you will need to provide the RPC endpoint URL of Wireshape Floripa Testnet in your script, like below:

Wireshape Floripa Testnet RPC URL
// RPC endpoint URL of Wireshape Floripa Testnet network
const rpcURL = "rpc-floripa.wireshape.org";

With the web3.js capabilities, developers can harness the power of the Wireshape Blockchain to build innovative decentralized applications, facilitate secure transactions, and automate processes through smart contracts. Let's delve into how to implement these functionalities using Web3.js.

Example of a Script

Wireshape blockchain is a EVM-compatible blockchain and Wire (WIRE) is its native token, like Ether (ETH) for Ethereum, so here is a basic example of a web3.js script that connects to the Wireshape RPC network and gets a wallet balance:

const Web3 = require("web3");

// RPC endpoint URL of Wireshape Floripa Testnet network
const rpcURL = "rpc-floripa.wireshape.org";

// Instantiating Web3 provider
const web3 = new Web3(rpcURL);

// Wallet address you want to check the balance for
const walletAddress = "0x..."; // Replace with your wallet address

// Function to get the wallet balance
async function getBalance() {
try {
// Getting the wallet balance
const balance = await web3.eth.getBalance(walletAddress);

// Converting balance from Wei to Wire
const balanceInWire = web3.utils.fromWei(balance, "ether");

console.log("Wallet balance:", balanceInWire, "WIRE");
} catch (error) {
console.error("An error occurred while fetching the wallet balance:", error);
}
}

// Calling the function to get the wallet balance
getBalance();
note

Make sure to replace '0x...' with the wallet address you want to check the balance.

After running this example script, you will have obtained the balance of a specific wallet address in Wire on the Wireshape Floripa Testnet network. By connecting to the RPC endpoint provided by Wireshape and utilizing the Web3.js library, the script retrieves the wallet's balance and converts it from Wei to Wire.

info

Check out the units used in EVM-compatible blockchains in the EVM section.