Skip to main content
Version: 1.0

Viem

Viem is a cutting-edge TypeScript interface designed for seamless interaction with the Ethereum Virtual Machine (EVM) and EVM-compatible networks like Wireshape. It prioritizes reliability, speed, and an exceptional developer experience, offering lean primitives for blockchain operations. Viem enables developers to efficiently perform tasks such as signing transactions, executing smart contracts, and handling event responses, making it an indispensable tool in the development of decentralized applications (dApps).

Core Capabilities of Viem

Viem simplifies the development process for Ethereum and EVM-compatible applications by providing a streamlined interface with essential functionalities:

Transaction Management

  • Offers a robust framework for creating, signing, and sending transactions, including support for WIRE transfers and smart contract interactions.

  • Ensures secure and efficient transaction management within the Wireshape ecosystem.

Smart Contract Interaction

  • Enables straightforward interaction with smart contracts, supporting the deployment of new contracts, invocation of contract functions, and event subscription.

  • Facilitates enhanced dApp functionalities and user engagement through seamless contract integration.

Event Listening

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

  • Essential for developing responsive and interactive applications on the Wireshape platform.

Setting Up Viem

To start using Viem in your project, install it via npm:

npm install viem

Interacting with the Wireshape Blockchain

Configuring Viem for interaction with the Wireshape network involves setting up a connection to the Wireshape Floripa Testnet RPC endpoint:

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

Viem's design caters to developers seeking to leverage the Wireshape Blockchain for innovative dApp development, secure transactions, and smart contract automation.

Example of a Script

Given that Wireshape is an EVM-compatible blockchain with Wire (WIRE) as its native token, similar to Ether (ETH) for Ethereum, here is a basic example of a Viem script for connecting to the Wireshape RPC network and retrieving a wallet balance:

import { Viem, HttpProvider } from "viem";

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

// Creating an instance of Viem with the RPC URL
const viem = new Viem(new HttpProvider(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 viem.getBalance(walletAddress);

// Converting balance from Wei to Wire
const balanceInWire = Viem.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 Viem 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.