How do transaction verification and adding a block to the blockchain fit together?
Verification of transactions is performed by every participant in the Bitcoin network. Participants include normal wallets and are usually referred to as nodes.
Only miners create new blocks. Thereby confirming the transactions in them.
Note the important distinction between verification and confirmation.
How is a transaction added to a block?
A miner selects unconfirmed transactions and adds them to a block template. When they find an arrangement whose hash is less than the current target they send the new block to some other network nodes.
Do miners get a reward for adding a transaction to a block?
Yes, the difference between sum of inputs and sum of outputs is a transaction fee that the miner claims.
How is that block then added to the blockchain?
Each node validates the new blocks it receives and decides whether to add the new block to their own copy of the blockchain. If a node has tested a block and found it to be valid, it will also pass on the block to other nodes.
If everyone (miners) are solving the block and adding a transaction, then how is it decided whose block will be added to the blockchain?
Every miner's draft block is different because the first transaction in a block is one that pays rewards/fees to that miner's own address.
First block received by a node is added to the current branch. Then by comparing total "work" in competing branches a node may choose another branch as the current branch.
Work is essentially an assessment of the average number of rearrangements of a block that would theoretically have to be attempted to find one whose hash is less than the target applicable to the block-height of the block. It doesn't measure how many attempts a miner actually made.
The target is reassessed every 2016 blocks and is given a value that will tend to make the average time between blocks be 10 minutes. Every node calculates these targets independently using common rules applied to blockchain data for those 2016 blocks.
Also, for example, if there are two miners A and B, and if miner A's block is added then what will happen to the transactions [
verified confirmed] by miner B?
Nodes that follow A's branch will consider transactions that are only in B's block to be unconfirmed. A or another miner will probably include them in a later block that references A's block (i.e. one that builds on a chain that includes A's block but not B's).