Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Whale Watch Example - Tokens

node v10.24.1
version: 1.0.0
endpointsharetweet
const Web3Data = require("web3data-js@0.6.1") // Set the blockchainId of the blockchain to listen on const blockchainId = '1c9c969065fcd1cf' // ethereum-mainnet // Create the Web3Data instances passing in your API Key (Get one! -> amberdata.io/onboarding) const w3d = new Web3Data(process.env.API_KEY, {blockchainId}) // Use these parameters to adjust the threshold value and the comparison operator const thresholdValue = 10 const thresholdSign = '>' w3d.connect() w3d.on({eventName: 'token_transfers'}, async transfer => { const {name, decimals} = await w3d.address.getInformation(transfer.tokenAddress) const txnValue = transfer.amount / Math.pow(10, decimals) if(meetsThreshold(txnValue, thresholdValue, thresholdSign)) { const time = transfer.timestamp ? (new Date(transfer.timestamp) ).toLocaleString() : null console.log(`New transfer - TxnHash: ${transfer.transactionHash.slice(0,10)} Token: ${name} Amount: ${round(txnValue, 2)} Time: ${time}`) } }) // Simple helper function for rounding const round = (n, digits) => Number.parseFloat(n).toFixed(digits) // Function that returns whether or not the threshold gets met const meetsThreshold = (value, thresholdValue, thresholdSign) => { switch (thresholdSign) { case '>': return value > thresholdValue case '<': return value < thresholdValue case '≥': return value >= thresholdValue case '≤': return value <= thresholdValue default: break } }
Loading…

no comments

    sign in to comment