Web Client vs RPC Client

Choose the right tool for interacting with the Nimiq blockchain

If you're unsure which client to use for interacting with the Nimiq blockchain, this guide will help you choose the tool that best fits your needs and expertise.

TL;DR

FeatureWeb ClientRPC Client
ConnectionDirect peer connectionsClient-server model
Network RolePart of blockchain networkThrough intermediary node
TechnologyJavaScript/WebAssemblyLanguage agnostic (HTTP)
RuntimeBrowser and Node.jsAny platform
ArchitectureLightweight and mobile-friendlyFull-featured server setup

Getting Started

Web Client vs RPC Architecture

Comparison Overview

CategoryWeb ClientRPC Client
ImplementationJavaScript/WebAssemblyHTTP/JSON-RPC
Network ModelDirect peer connectionsClient-server model
EnvironmentBrowsers, Node.js, mobileAny platform
Best ForWeb wallets, DAppsExchanges, Explorers
Node TypeLight nodeFull/History node
Setup TimeMinutes (NPM install)Hours (Node setup)
InfrastructureBrowser environmentDedicated server
LanguageJavaScript/TypeScriptAny language
Target UsersWeb developers, end usersSystem integrators
Data AccessRecent blockchain dataComplete history

Detailed Comparison

Web Client

The Web Client is a JavaScript library enabling direct participation in the Nimiq PoS ecosystem:

  • Implementation: Rust compiled to WebAssembly using wasm-pack
  • Environment: Browsers, Node.js, mobile devices
  • Browser Support: Chrome, Firefox, Edge, Safari
  • User Experience: Simple, intuitive interface
  • Key Operations:
    • Create and manage wallets
    • Send transactions
    • View transaction history
    • Check balances
    • Build consensus with peers
'use client';
import { useEffect, useState } from 'react';
import { Client } from '@nimiq/core-web';
 
function NimiqWebClient() {
  const [balance, setBalance] = useState<number | null>(null);
  const [isConnected, setIsConnected] = useState(false);
  const address = 'NQ05 U1RF QJNH JCS1 RDQX 4M3Y 60KR K6CN 5LKC';
 
  useEffect(() => {
    const client = new Client({
      network: 'test',
      consensus: 'light'
    });
 
    async function init() {
      try {
        await client.waitForConsensus();
        setIsConnected(true);
        
        const addressBalance = await client.getBalance(address);
        setBalance(addressBalance);
      } catch (error) {
        console.error('Nimiq Client Error:', error);
      }
    }
 
    init();
  }, []);
 
  return (
    <div className="space-y-4">
      <div>Status: {isConnected ? 'Connected' : 'Connecting...'}</div>
      <div>Balance: {balance !== null ? `${balance} NIM` : 'Loading...'}</div>
    </div>
  );
}

Key Features:

  • Browser and Node.js compatible
  • WebAssembly-powered
  • Direct peer connections
  • Lightweight consensus
  • Simple wallet operations

RPC Client

The RPC provides advanced node access and control:

  • Implementation: JSON-RPC over HTTP
  • Environment: Any platform with HTTP capabilities
  • Access Level: Full node control
  • User Experience: Technical, API-focused
  • Key Operations:
    • Lock/unlock accounts
    • Verify transactions
    • Manage accounts
    • Configure node settings
    • Access blockchain state
'use client';
import { useState, useEffect } from 'react';
 
function NimiqRPC() {
  const [blockNumber, setBlockNumber] = useState<number | null>(null);
  const [balance, setBalance] = useState<number | null>(null);
  const rpcUrl = 'https://yourRpcUrl';
  const address = 'NQ05 U1RF QJNH JCS1 RDQX 4M3Y 60KR K6CN 5LKC';
 
  const fetchRpcData = async () => {
    try {
      // Get latest block
      const blockResponse = await fetch(rpcUrl, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          jsonrpc: '2.0',
          method: 'getBlockNumber',
          params: [],
          id: 1
        })
      });
      const blockData = await blockResponse.json();
      setBlockNumber(blockData.result);
 
      // Get balance
      const balanceResponse = await fetch(rpcUrl, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          jsonrpc: '2.0',
          method: 'getBalance',
          params: [address],
          id: 2
        })
      });
      const balanceData = await balanceResponse.json();
      setBalance(balanceData.result);
    } catch (error) {
      console.error('RPC Error:', error);
    }
  };
 
  useEffect(() => {
    fetchRpcData();
    const interval = setInterval(fetchRpcData, 10000);
    return () => clearInterval(interval);
  }, []);
 
  return (
    <div className="space-y-4">
      <div>Current Block: {blockNumber ?? 'Loading...'}</div>
      <div>Balance: {balance !== null ? `${balance} NIM` : 'Loading...'}</div>
    </div>
  );
}

Use Cases & Operations

CapabilityWeb ClientRPC Client
Wallet Integration✓ Web wallets
✓ Simple transactions
✓ Balance checks
✓ Exchange integration
✓ Complex operations
✓ Account management
Node Management✓ Light consensus
✓ Direct peer connections
✓ Browser-based
✓ Full node control
✓ Custom configuration
✓ Advanced settings
Development✓ Frontend focused
✓ Quick setup
✓ Mobile friendly
✓ Backend services
✓ Advanced API access
✓ Multi-language support

Getting Started

Learn More

Interested in the technical details? Check out the Nimiq Albatross Protocol Documentation.

On this page