It depends on the tool/library you are using.
If you are using web3js, you can leverage the "receipt" or "confirmation" event emitter.
"receipt": Fired when the transaction receipt is available.
"confirmation": Fired for every confirmation up to the 12th confirmation. Receives the confirmation number as the first and the receipt as the second argument. Fired from confirmation 0 on, which is the block where it’s mined.
Below is a sample code with sendTransaction method:
// using the event emitter
web3.eth.sendTransaction({
from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe',
to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
value: '1000000000000000'
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('confirmation', function(confirmationNumber, receipt){ ... })
.on('error', console.error); // If a out of gas error, the second parameter is the receipt.
For Ethers.js transaction.wait
is part of the transaction response, it is resolved when the transaction is confirmed.
Resolves to the TransactionReceipt once the transaction has been
included in the chain for confirms blocks. If confirms is 0, and the
transaction has not been mined, null is returned.