BlockDAG Docs
  • 🎯Introduction to BlockDAG
  • ⭐GETTING STARTED
    • What is BDAG?
    • Introductory Concepts
      • Decentralized Application (dApps)
      • Accounts
        • EVM Account
        • UTXO Account
      • Transactions
      • Blocks
      • EVM
        • Opcodes
      • Gas Fees
    • Nodes and Mining
      • Testnet Node Setup
    • BlockDAG Architecture
      • Architecture Overview
      • Core Modules and Components
      • Development and Implementation
      • Blockchain Features
      • Consensus Algorithm
  • TEST/MAIN NETWORKS
    • Testnet Alpha
    • Testnet Beta 1: Primordial
      • Network Details
  • BlockDAG Tools
    • Block Explorer
    • Faucet
    • Smart Contract IDE
      • IDE Layout
      • How to create and deploy
    • Contracts Wizard
  • BlockDAG Client APIs
    • EVM RPC
    • WebSocket
  • BlockDAG dApps
    • Create dApps
    • dApps Overview
    • Reflection User Guide
      • Home
      • Reflection Dashboard
      • Reflection
    • Lottery User Guide
      • Lottery Dashboard
      • Lottery
      • Participants
  • Block Explorer
    • EVM
      • Home
      • Block List
        • Block Detail
      • Transaction List
        • Transaction Detail
      • Address Details
      • Contract Listing
        • Contract Details
          • Transfer Tab
          • Holders Tab
          • Events Tab
          • Info Tab
          • Contract Tab
            • Code Tab
            • Read Tab
            • Write Tab
        • Contract Owner
        • Contract Verification
        • Contract Transaction Details
      • Tokens List
        • Token Detail
          • Transfer Tab
            • Transfer Detail Tab (Overview)
            • Transfer Detail (Logs)
          • Holders Tab
            • Holders Detail
          • Events Tab
          • Info Tab
          • Contracts Tab
        • Token Transfer
      • Node Visualizer
      • Faucet
    • UTXO
      • UTXO Home
      • Block List (UTXO)
        • Block Details (UTXO)
      • Transaction List (UTXO)
        • Transaction Details (UTXO)
      • Address Details (UTXO)
Powered by GitBook

Copyright © BlockDAG

On this page
  • Introduction
  • Key Features
  • Technical Details
  • Supported RPC Methods
  • Benefits in BlockDAG Explorer
  • Best Practices for Developers
  • Conclusion

Was this helpful?

Edit on GitHub
  1. BlockDAG Client APIs

WebSocket

This section provides detailed information on using WebSocket RPC connections for interacting with the BlockDAG blockchain, a Layer 1 proof-of-work network leveraging a Directed Acyclic Graph (DAG) structure for high-speed, secure, and decentralized transactions. WebSocket RPC enables real-time, bi-directional communication, making it ideal for decentralized applications (dApps) requiring live updates, such as transaction confirmations or block additions.

Introduction

WebSocket RPC facilitates seamless interaction with the blockchain by establishing a persistent, full connection over TCP. Unlike traditional HTTP-based RPC, which requires repeated polling, WebSocket RPC allows clients to receive real-time updates, reducing latency and improving efficiency. This is particularly valuable for applications like the BlockDAG Explorer, where users need immediate visibility into network activity.

Key Features

The WebSocket RPC implementation in BlockDAG offers several advantages:

  • Real-time Communication: Enables bi-directional, full-duplex communication over a single TCP connection, allowing instantaneous data exchange between clients and the blockchain.

  • Enhanced User Experience: Supports live updates for dApps, such as real-time block notifications and transaction confirmations, eliminating the need for manual page refreshes.

  • Scalability and Performance: Optimized for high throughput and low latency, capable of handling large data volumes and numerous simultaneous users, making it suitable for high-traffic applications.

  • Security: Utilizes Secure WebSocket (wss://) for encrypted communication, with authentication mechanisms like token-based access to protect RPC methods.

Technical Details

The WebSocket RPC implementation adheres to industry standards and incorporates optimizations for performance and compatibility:

  • Protocol: Follows the RFC 6455 WebSocket standard, supporting both unencrypted (ws://) and encrypted (wss://) connections. Secure connections are recommended for production environments.

  • Language Compatibility: Compatible with various programming languages through libraries and SDKs, including Python (websocket-client), JavaScript (ws), Go (gorilla/websocket), and C++ (libwebsockets).

  • Optimization:

    • Message Batching: Groups multiple messages to reduce overhead and improve throughput.

    • Compression: Uses permessage-deflate to minimize bandwidth usage.

    • Memory Management: Optimized to handle high loads efficiently, ensuring stability under heavy traffic.

  • Backward Compatibility: Designed to work seamlessly with existing RPC interfaces, allowing developers to transition from HTTP-based RPC without significant code changes.

Supported RPC Methods

BlockDAG’s WebSocket RPC supports a range of methods for interacting with the blockchain, as outlined in Dev Release 22. These methods enable developers to query data, execute transactions, and interact with smart contracts. The following table summarizes the key methods:

Method

Description

Function Signature

getBalance

Retrieves the balance for a given account or address.

getBalance(address)

sendTransaction

Initiates and broadcasts a transaction from one account to another.

sendTransaction(sender, recipient, amount, gasLimit, gasPrice)

getBlock

Retrieves details about a specific block on the blockchain.

getBlock(blockNumber)

getTransaction

Fetches detailed information about a transaction using its hash.

getTransaction(transactionHash)

callSmartContractMethod

Executes specific functions on smart contracts.

callSmartContractMethod(contractAddress, methodName, args)

Benefits in BlockDAG Explorer

The integration of WebSocket RPC significantly enhances the functionality of the BlockDAG Explorer, a web-based tool for navigating the blockchain. Key benefits include:

  • Real-time Block Updates: New blocks are displayed immediately as they are added, providing users with up-to-date network information.

  • Live Transaction Feed: Transactions appear as they are confirmed, enabling real-time monitoring of network activity.

  • Enhanced User Experience: The explorer offers a dynamic, responsive interface, improving usability for both casual users and developers.

  • Scalability: The WebSocket implementation supports high data volumes, ensuring the explorer remains performant even with increased network activity.

These features make the BlockDAG Explorer a powerful tool for tracking transactions, analyzing blocks, and interacting with smart contracts in real time.

Best Practices for Developers

To effectively use BlockDAG’s WebSocket RPC, developers should follow these guidelines:

  • Use Secure Connections: Always use wss:// endpoints to ensure data privacy and security.

  • Handle Reconnections: Implement logic to automatically reconnect in case of connection drops, using exponential backoff to avoid overwhelming the server.

  • Optimize Payloads: Leverage message batching and compression to minimize bandwidth usage, especially for high-frequency requests.

  • Monitor Rate Limits: Check for any rate limits or throttling policies in the official documentation to avoid being blocked.

  • Test on Testnet: Use the BlockDAG Primordial Testnet to experiment with WebSocket RPC before deploying to mainnet, ensuring compatibility and performance.

Conclusion

BlockDAG’s WebSocket RPC implementation represents a significant advancement in blockchain interactivity, offering real-time communication, scalability, and security for dApps and tools like the BlockDAG Explorer. By supporting key RPC methods and planning future enhancements, BlockDAG is well-positioned to meet the needs of developers building on its high-speed, decentralized network. For the latest endpoint details and API documentation, refer to the BlockDAG Developer Hub.

PreviousEVM RPCNextCreate dApps

Last updated 9 days ago

Was this helpful?