Querying the Blockchain

Once you have imported Brambl, you can do many read-only requests without needing to import any other modules which you can use to query the current state, fetch historical information, and so on.

Get Latest Block: Requests the latest block from the chain provider

val params: Head.Params = ToplRpc.NodeView.Head.Params()
val response: RpcErrorOr[Head.Response] = ToplRpc.NodeView.Head.rpc(params)

Get a particular block by height

val params: BlockByHeight.Params = ToplRpc.NodeView.BlockByHeight.Params(height)
  val response: RpcErrorOr[BlockByHeight.Response] = ToplRpc.NodeView.BlockByHeight.rpc(params)

Get the balance on addresses

val params: Balances.Params = ToplRpc.NodeView.Balances.Params(externalAddress.toList)
val response: RpcErrorOr[Balances.Response] = ToplRpc.NodeView.Balances.rpc(params)

Get the latest 100 transactions from the Mempool

val params: Mempool.Params = ToplRpc.NodeView.Mempool.Params()

Lookup an UNCONFIRMED transaction by id (a transaction in the mempool)

val response: RpcErrorOr[TransactionFromMempool.Response] = for {
    params <- GetHeadOfChain.response.map { head =>
    transaction <- ToplRpc.NodeView.TransactionFromMempool.rpc(params)
  } yield transaction

Lookup a CONFIRMED transaction by id (a transaction in a block)

val response: RpcErrorOr[TransactionById.Response] = for {
    params <- GetHeadOfChain.response.map { head =>
    transaction <- ToplRpc.NodeView.TransactionById.rpc(params)
  } yield transaction

Lookup Block by Id

val response: RpcErrorOr[BlockById.Response] = for {
    params <- GetHeadOfChain.response.map(head => ToplRpc.NodeView.BlockById.Params(head.bestBlockId))
    block  <- ToplRpc.NodeView.BlockById.rpc(params)
  } yield block