Created
October 18, 2018 07:19
-
-
Save JasoonS/c701d3b68c2f804528bfa6a069ca8632 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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