W Chain Docs
W Chain Website
  • 🚀Welcome to W Chain
    • 📖Introduction and Overview
    • 🛰️Key Features That Make W Chain
  • Working with a Node
    • 🖥️Node
      • 🛠️Non-Validator Node Setup
      • 📦Validator Node Setup
    • ⚙️W Chain Client APIs
      • 🔄JSON-RPC
      • 🔌gRPC
  • 🤝Consensus
    • 🛡️Proof of Stake
  • 🏗️Architecture
    • W Chain Layer
  • ⚡Advanced Features
    • 🔍Explorer
    • ⛓️Bridge
    • 🧩DApps Integration
  • 💡Tutorial
    • 📲Web3 Wallet Setup
    • 📜Smart contract
  • Audit Reports
Powered by GitBook
On this page
Export as PDF
  1. Working with a Node
  2. W Chain Client APIs

JSON-RPC

JSON-RPC is a remote procedure call (RPC) protocol encoded in JSON (JavaScript Object Notation).

It allows developers to interact with the blockchain by sending HTTP requests to a W Chain node. JSON-RPC provides a simple and lightweight way to execute methods on a remote server (in this case, a W Chain node) and retrieve data such as account balances, transaction details, and smart contract states.

Purpose in W Chain: In W Chain, JSON-RPC is used to facilitate communication between decentralized applications (dApps) and the blockchain. Developers can use JSON-RPC to:

  • Query blockchain data (e.g., account balances, block details).

  • Submit transactions to the network.

  • Interact with deployed smart contracts.

  • Monitor blockchain events in real-time.

JSON-RPC is essential for integrating W Chain with external applications, enabling seamless blockchain interaction over HTTP or WebSockets.

Transaction, State, History

The core JSON-RPC methods for W Chain can be categorized into three main areas: Transaction, State, and History. These methods allow developers to interact with W Chain's data, whether they need to send transactions, query the current state of accounts, or access historical blockchain data. Use the links to explore each method.

Methods

  • eth_blockNumber

  • eth_chainId

  • eth_gasPrice

  • eth_getLogs

  • eth_getBalance

  • eth_getTransactionByHash

  • eth_getTransactionReceipt

  • eth_maxPriorityFeePerGas

Example Usage of JSON-RPC in W Chain

Querying Account Balance

One common use case for JSON-RPC is querying an account's balance. This is important for developers to determine whether an account has sufficient funds for transactions.

Command:

curl https://rpc.w-chain.com -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x0000000000000000000000000000000000001001", "latest"],"id":1}'

Explanation: This JSON-RPC request retrieves the current balance of the specified account (0x0000000000000000000000000000000000001001). The balance is returned as hexadecimals number in Wei, the smallest unit of EVM native currency, you need to factor the 18 decimals to get the human readable format.

Returned Value:

{
   "jsonrpc":"2.0",
   "id":1,
   "result":"0x22b1c8c1227a00000"
}

Submit a Transaction

Developers can also use JSON-RPC to send transactions to the W Chain network, allowing them to move tokens or interact with smart contracts.

PreviousW Chain Client APIsNextgRPC

Last updated 1 month ago

⚙️
🔄