Calculate Transaction Confirmations I am writing an API for one of my systems which can verify if a monitored address is receiving Bitcoin, I can already check if the address is on the newly received block, save it to a database for future use as UTXO, it is being managed pretty well.

I am just running into an issue. Since raw blocks do not hold the height information, how can I calculate (without using any external API) my database stored transaction confirmations? It does not make any sense also in my architecture RPC calls for that.
For this task, it's better to run a full-node with the transaction indexing txindex=1. Then you can get the number of confirmations from the txid of a transaction by calling:

bitcoin-cli getrawtransaction "txid" true and checking under the field confirmations. If you have jq installed you can call for example bitcoin-cli getrawtransaction 64749d0a6ab7292ed7445609e1adb8df8d67b29e344d752971699ca75bbda78e true | jq '.confirmations' and you get your answer.

In case you are not running your node with the txindex=1 option, you need to loop through the blocks to find your transaction and the number of confirmations is obtained by subtracting the block height of the transaction from the block count. You could check if the transaction is in a block like this:

bitcoin-cli getblock $(bitcoin-cli getblockhash 610321) | jq '.tx' | grep 210d8e526f4d3f72f7cdc9014ef057aa4654f64a7b1bd059f2d8dea7fcce79cd


If the command above returns anything, the transaction is in that block.