Using Web3 Libraries

If you’re building an application, web3 libraries provide a higher-level interface for interacting with Conduit RPC endpoints. They handle request formatting, response parsing, and type safety so you don’t have to work with raw JSON-RPC directly.

Replace [YOUR_RPC_URL] and [YOUR_API_KEY] with your values from the Conduit App.

eth_blockNumber

Get the latest block number.

import { createPublicClient, http } from 'viem'
const client = createPublicClient({
transport: http('https://[YOUR_RPC_URL]/[YOUR_API_KEY]'),
})
const blockNumber = await client.getBlockNumber()
console.log(blockNumber)

eth_getBalance

Get the ETH balance of an address.

const balance = await client.getBalance({
address: '0xYOUR_ADDRESS',
})
console.log(balance)

eth_call

Call a contract function without sending a transaction.

const result = await client.call({
to: '0xCONTRACT_ADDRESS',
data: '0xCALLDATA',
})
console.log(result.data)

eth_getLogs

Fetch logs matching a filter. See Throughput for block range and event count limits.

const logs = await client.getLogs({
address: '0xCONTRACT_ADDRESS',
fromBlock: 0n,
toBlock: 'latest',
})
console.log(logs)

eth_sendRawTransaction

Sign and broadcast a transaction.

import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
const account = privateKeyToAccount('0xYOUR_PRIVATE_KEY')
const walletClient = createWalletClient({
account,
transport: http('https://[YOUR_RPC_URL]/[YOUR_API_KEY]'),
})
const hash = await walletClient.sendTransaction({
to: '0xRECIPIENT_ADDRESS',
value: 1000000000000000n,
})
console.log(hash)

eth_subscribe (WebSocket)

Subscribe to new block headers in real time. This requires a WebSocket connection with an API key appended to the WSS URL. Starting August 4, 2026, anonymous WebSocket connections are rejected. See WebSockets for connection management guidance.

import { createPublicClient, webSocket } from 'viem'
const client = createPublicClient({
transport: webSocket('wss://[YOUR_RPC_URL]/[YOUR_API_KEY]'),
})
const unwatch = client.watchBlocks({
onBlock: (block) => console.log(block),
})