What is @walletconnect/jsonrpc-types?
@walletconnect/jsonrpc-types is a TypeScript library that provides type definitions for JSON-RPC (Remote Procedure Call) methods and responses. It is primarily used in the context of WalletConnect, a protocol for connecting decentralized applications (dApps) to mobile wallets with QR code scanning or deep linking.
What are @walletconnect/jsonrpc-types's main functionalities?
Type Definitions for JSON-RPC Methods
This feature provides type definitions for JSON-RPC requests, ensuring that the request object adheres to the expected structure.
import { IJsonRpcRequest } from '@walletconnect/jsonrpc-types';
const request: IJsonRpcRequest = {
id: 1,
jsonrpc: '2.0',
method: 'eth_sendTransaction',
params: [{
from: '0x1234567890abcdef1234567890abcdef12345678',
to: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
value: '0x1',
gas: '0x5208',
gasPrice: '0x3b9aca00',
nonce: '0x0',
data: '0x'
}]
};
Type Definitions for JSON-RPC Responses
This feature provides type definitions for JSON-RPC responses, including both success and error responses, ensuring that the response objects adhere to the expected structure.
import { IJsonRpcResponseSuccess, IJsonRpcResponseError } from '@walletconnect/jsonrpc-types';
const successResponse: IJsonRpcResponseSuccess = {
id: 1,
jsonrpc: '2.0',
result: '0x1'
};
const errorResponse: IJsonRpcResponseError = {
id: 1,
jsonrpc: '2.0',
error: {
code: -32600,
message: 'Invalid Request'
}
};
Type Definitions for JSON-RPC Errors
This feature provides type definitions for JSON-RPC errors, ensuring that error objects adhere to the expected structure.
import { IJsonRpcError } from '@walletconnect/jsonrpc-types';
const error: IJsonRpcError = {
code: -32601,
message: 'Method not found'
};
Other packages similar to @walletconnect/jsonrpc-types
json-rpc-engine
json-rpc-engine is a JavaScript library for building JSON-RPC middleware stacks. It provides a flexible and modular approach to handling JSON-RPC requests and responses. Unlike @walletconnect/jsonrpc-types, which focuses on type definitions, json-rpc-engine provides a full implementation for handling JSON-RPC communication.
jsonrpc-lite
jsonrpc-lite is a lightweight JavaScript library for JSON-RPC 2.0. It provides utilities for parsing, validating, and serializing JSON-RPC requests and responses. While @walletconnect/jsonrpc-types focuses on type definitions, jsonrpc-lite offers a more comprehensive set of tools for working with JSON-RPC.