Skip to main content

Supported RPC Methods

  • eth_blockNumber
  • eth_chainId
  • eth_getBlockByHash
  • eth_getBlockByNumber
  • eth_getBlockTransactionCountByHash
  • eth_getBlockTransactionCountByNumber
  • eth_getTransactionByHash
  • eth_getTransactionByBlockHashAndIndex
  • eth_getTransactionByBlockNumberAndIndex
  • eth_getTransactionReceipt
  • eth_getBalance
  • eth_getStorageAt
  • eth_getTransactionCount
  • eth_call
  • eth_getLogs

Of course, with eth_call you can call any new view functions you added to your contracts along with pre-existing functions. With eth_getLogs you can filter by both ghost logs and pre-existing, traditional logs.

WebSocket methods

  • eth_subscribe for newHeads and logs

Example: subscribing to our newly added event for blend repayments (the original contract Repay event only emits the lienId and collection). After adding a new RepayDetails event with a lot more information, we can subscribe to it like so:

Example subscription

import { EventFragment, Interface, WebSocket } from 'ethers'
// alternatively, use our ReconnectingWebsocketProvider
// import { ReconnectingWebsocketProvider } from './reconnecting_websocket'

const WS_URL = 'wss://ws.ghostlogs.xyz/<FORK_KEY_FROM_DASHBOARD>'
const BLEND = '0x29469395eAf6f95920E59F858042f0e28D98a20B'

async function run() {
// You can also use the ABI, but let's write it out new event here to be explicit
const blendRepayDetails = EventFragment.from(
`RepayDetails(uint256 lienId, address collection, uint256 tokenId,
address borrower, address lender,
uint256 amountBorrowed, uint256 amountRepaid, uint256 rate)`
)

const iface = new Interface([blendRepayDetails])
const topics = [blendRepayDetails.topicHash]

const provider = new WebSocket(WS_URL)
// const provider = ReconnectingWebsocketProvider.create(WS_URL)
console.log(`listening to ${WS_URL}`)
await provider.on({ address: BLEND, topics: [topics] }, (ev) => {
console.log(iface.decodeEventLog(blendRepayDetails, ev.data, ev.topics))
})
}

if (require.main === module) {
;(async () => {
await run()
})()
}