The Alternative Way (via RPC Polling)
Some of the SDKs do not yet support WebSocket subscriptions for RPC queries, so this may be the preferable option in some use cases.
You can use the Tx RPC method to query for the transaction and get its block height. Here is an example using the JavaScript SDK:
> rpc.tx({
hash: Buffer.from('B2EF71DAEB86385E64F6C0B923636ADE5510B3C34C07D19EE5A114FC9075273D', 'hex'),
prove:false
}).then(x => console.log('',x))
{
hash: 'B2EF71DAEB86385E64F6C0B923636ADE5510B3C34C07D19EE5A114FC9075273D',
height: '30261607',
index: 0,
tx_result: { log: 'Msg 0: ', tags: [ [Object], [Object], [Object] ] },
tx: '0AHwYl3uCkwqLIf6CiIKFLjeOPB9sCxE5v+lpkRhnPu+K1ahEgoKA0JOQhCMy5ZfEiIKFI6nDX0uqKFLorM9GNXfvW+uCm6oEgoKA0JOQhCMy5ZfEnEKJuta6YchA6Xy63LJBSKNsW1nkGMbPyvWl7VDeD/lVByJrtnB3v1kEkA243QKSCn5GxFSTFbh6EA8ZuqdO+0UTR8+Vq7CDikOzCIpuRo95Ww7zak0qXRmL3/shGkwHcvB4l9ofF61mSQgGKfQCSDDARoJMTAxNzg5MTEz'
}
If the Transaction does not yet exist in the blockchain, this attempt will return with an error.
You should check for an absent "code" field in the tx_result: this indicates a code of 0. You could also perform further checks on the log to make sure that it matches the expected value.
Last updated