Real-time Usage Monitoring

node v10.23.3
version: 1.0.0
endpointsharetweet
const Web3Data = require("web3data-js@0.6.1") // Create the Web3Data instances passing in your API Key (Get one! -> amberdata.io/onboarding) const w3d = new Web3Data(process.env.API_KEY) /* Helpers */ // Get the human readable text signature of the event const getTextSig = async (hashSig) => w3d.signature.getSignature(hashSig).then( data => data.length > 0 ? data[0].textSignature : '') // Init websocket connection w3d.connect() // Watch for contract events i.e. transfers, pregnant kitties ect. w3d.on({eventName:'address:logs', filters: {"address": cryptoKittiesContract} }, async data => { const hashSig = data.topics[0].slice(0, 10) const textSignature = await getTextSig(hashSig) // Construct a nice logging message to signal a new event const eventMessage = `event ${textSignature} at ${new Date(data.timestamp).toLocaleString()} in block ${data.blockNumber}` // Log to console console.log(textSignature !== '' ? eventMessage : `sig ${textSignature} not found`) }) // Watch for all new transactions w3d.on({eventName:'address:transactions', filters: {"address": cryptoKittiesContract} }, async data => { console.log(`New transaction ${data.hash.slice(0,10)} at ${data.timestamp}`) }) // Watch for all new pending transactions w3d.on({eventName:'address:pending_transactions', filters: {"address": cryptoKittiesContract} },(pending_txns) => { console.log(pending_txns) })
Loading…

no comments

    sign in to comment