I am bit confused about transaction broadcast on the internet.How does a miner know a transaction has been broadcasted? The internet network is very huge.Or how does my bitcoin client collects the blocks broadcasted?

2 Answers
2

Bitcoins P2P network is a flooding design, new transactions and blocks are broadcast to every connected peer, and they broadcast to every one of their peers. Valid data reaches all participants very quickly due to the random selection of peers that all nodes make. All validating participants keep a 'mempool', a collection of unconfirmed transactions they believe are valid, miners collect transactions they wish to include in blocks from their mempool and turn them into a candidate template to mine against.

Under the hood, Bitcoin has something called json-rpc. That is used within the software and with other software that you wish to integrate into bitcoin to send and receive payments, to generate wallet addresses, and to get network data. Bitcoin Core and any other software that stores a full copy of the blockchain (spv wallets like multi-bit, mycelium, and the android bitcoin wallet are light weight and do not put 60GB of blockchain transaction data on your phone).

They talk to each other through port 8333 and bitcoin transactions are sent to each other, broadcasted. If you had custom software on your computer where bitcoin core was running, you could program a script to have your application talk to bitcoin to first get inputs, then create a raw transaction, sign the transaction with the private key that holds spendable inputs, then to broadcast it. Looking at the process we see that sign transaction returns a Json array with the hex-encoded signed data, and a result code (most Bitcoin Op_Code script returns either 0 or 1 at the protocol level to signify failure (0) or success (1). Then the software sends the data (broadcasts it) to connected peers through port 8333 with that signed hex value. The protocol then returns either a transaction ID or an error, again as a Json object.