@rarcifa/cronos-evm-client
Version:
A Node.js client library for interacting with the Cronos EVM, facilitating operations on both CRC20 and CRC721 tokens.
24 lines (23 loc) • 981 B
JavaScript
/**
* This function creates the payload necessary for making JSON-RPC calls such as `eth_call`.
*
* @param {Object|string} param - An object containing the 'to' and 'data' properties for the RPC call, or the method signature.
* @param {string} method - The JSON-RPC method to be invoked (e.g., 'eth_call', 'eth_sendTransaction').
* @param {string} [tag='latest'] - The block number tag specifying the state to query or transact with. Common values are 'latest', 'earliest', or 'pending'.
* @param {number} [id=1] - A unique identifier for the JSON-RPC request, used to match responses with requests.
* @returns {object} The JSON-RPC payload formatted as an object.
*
* @example
* const data = constructEthMethodPayload(
* '0xE51.....2DAde05',
* 'eth_getBalance'
* );
*/
export const constructEthMethodPayload = (params, method, tag = 'latest', id = 1) => {
return {
jsonrpc: '2.0',
method,
params: [params, tag],
id,
};
};