Skip to content

Instantly share code, notes, and snippets.

@JasoonS
Created October 18, 2018 07:19
Show Gist options
  • Save JasoonS/c701d3b68c2f804528bfa6a069ca8632 to your computer and use it in GitHub Desktop.
Save JasoonS/c701d3b68c2f804528bfa6a069ca8632 to your computer and use it in GitHub Desktop.
const blockchainProxy = require('blockchain-proxy-client')({apiServerAddress: 'http://localhost:3000'})
const tokenProxy = require('token-proxy-client')({apiServerAddress: 'http://localhost:5000'})
async function subscribeToBalanceTopic() {
const [
{ contractAddress: tokenContractAddress },
{ prototype: availableBalanceTopic },
{ abi: tokenContractAbi },
] = await Promise.all([
tokenProxy.contractAddress(),
tokenProxy.getAvailableBalanceEventPrototype(),
tokenProxy.getTokenContractABI(),
])
console.log(availableBalanceTopic)
const sseAvailableBalanceEvents = blockchainProxy.subscribeToBalanceTopicToContractEvents(
tokenContractAddress,
tokenContractAbi,
JSON.stringify({
fromBlock: 0,
topics: [availableBalanceTopic]
}),
event => {
const eventData = JSON.parse(event.data)
console.log(eventData)
}
)
}
subscribeToBalanceTopic()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment