Overview
The SDK supports Core JSON-RPC API functionality for its supported chains. These functions are provided by viem.
Core RPC Method to SDK Function
The following is a list of supported Core RPC methods and the equivalent viem function available to the SDK. Please see the linked Core RPC method documentation for the example SDK usage, and the linked viem docs for the equivalent function documentation.
More helper functions are available for Core RPC calls through viem. For more information about how to utilize viem and its helper functions, see the Viem Integration page.
Example: Get Balance
To call the eth_getBalance RPC method, you can use the getBalance function.
import { Core } from '@quicknode/sdk';
const core = new Core({
endpointUrl: "https://my-endpoint-name.quiknode.pro/myauthtoken/",
});
core.client.getBalance({
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
}).then(balance => console.log(balance))
How to Call RPC Methods Directly
Not all RPC methods have a corresponding function at this time. To call an RPC method directly, the client.request()
function can be used.
For example, here is how to call trace_block:
import { Core } from '@quicknode/sdk';
const core = new Core({
endpointUrl: "https://my-endpoint-name.quiknode.pro/myauthtoken/",
});
core.client.request({
method: "trace_block",
params: ["0xccb93d"],
}).then(traceBlock => console.log(traceBlock));
In TypeScript, the RPCSchemaOverride
type from viem needs to be passed into the request
generic to avoid type errors. Please be aware this function and the response will not have complete type safety.
import { Core, viem } from '@quicknode/sdk';
const core = new Core({
endpointUrl: "https://my-endpoint-name.quiknode.pro/myauthtoken/",
});
core.client.request<viem.RpcSchemaOverride>({
method: "trace_block",
params: ["0xccb93d"],
}).then(traceBlock => console.log(traceBlock));