The standard way to track extrinsics is:
api.tx.balances
.transfer(recipient, 123)
.signAndSend(sender, ({ status, events }) => {
if (status.isInBlock) {
// here we know that our tx is in chain and can check if it succeeded or not
}
})
I need to support a case where something can go wrong on client before extrinsic gets in the block, so I'm looking for something like this:
let txHash = await api.tx.balances
.transfer(recipient, 123)
.signAndSend(sender);
store_hash_in_db(txHash);
// later somewhere else in the code, for example after server restart or page refresh
let txHash = load_hash_from_db();
// how to check here if extrinsic got included in block and in which one?
I'm aware that tx hash isn't a unique identifier and block hash + index should be used instead (https://wiki.polkadot.network/docs/build-protocol-info#unique-identifiers-for-extrinsics), but that only works if I wait until transaction gets included, which may be a long time during which things can go wrong.
What's the solution here?