libcardano
v1.4.11
Published
Cardano Node JS ================
Downloads
631
Readme
Cardano Node JS
Components:
1.Interceptor
It intercepts connection between two cardano-nodes. The communication is logged with decoded protocol messages.
example:
##
## [[ Node1 ]] ----->> [127.0.0.1:3001 [[Interceptor]]] ----->> [172.31.0.15:3002 [[Node 2]]]
##
yarn interceptor 0.0.0.0:3001 172.31.0.15:3002
2.Client
Attempts connection to remote node and
- maintain connection with it with periodic ping
- log all the communication to/from the server
example:
yarn client preview-node.world.dev.cardano.org:30002
3. Using As a Library
3.1 Following a node for latest transactions.
import { createInMemoryClientWithPeer } from "libcardano/helper"
import {parseRawBlockBody} from "libcardano/cardano/ledger-serialization/transaction";
import * as process from "process";
const blockchain = createInMemoryClientWithPeer(process.argv[2]|| "sanchonet-node.play.dev.cardano.org:3001",{
networkMagic: parseInt(process.argv[3]) || 4,
startPoint:'Latest'
})
blockchain.on("extendBlock", (block) => {
const transactions = parseRawBlockBody(block.body)
console.log("RollForward :", block.headerHash.toString('hex'), "blockNo:", block.blockNo, "slotNo:", block.slotNo,"txCount:",transactions.length)
})
blockchain.pipeline("rollback",([[slot,headerHash], blockNo],_currentTip, cb)=>{
console.log("Rollback :",headerHash.toString('hex'), "blockNo:",blockNo,"slotNo:",slot )
setImmediate(cb)
})