1

When using a wallet such as Metamask that uses a blockchain node provider to connect you to the blockchain:

  1. Does the smart contract get mined to specifically that node and then the other update their blockchain nodes?

  2. What is the miners role in all of this? (does he actually mine it to the provider node)

1 Answer 1

0
  1. When Metamask sends a transaction to its node provider, the node will first check that is a valid transaction and then send it across the network, to all the nodes that it knows. Then all those neighbor nodes will do the same and send that transaction to all the nodes they know, eventually reaching mining nodes that will also broadcast it and try to mine it. Once it is mined, then the miner will broadcast the block containing that transaction to all its known nodes, which in turn will do the same, until the new block is broadcasted network-wise. So, the Metamask node provider doesn't really have to be a miner node, and if it was, it wouldn't try to mine it alone, but broadcast it and then try to mine it, this way it would have a chance to get into the next block within the expected average 15 seconds.

  2. Well, I think that my answer to your first question also answers this one. Since the transaction is broadcasted to the network, a random miner will mine the block containing that transaction, which will then be broadcasted to the network and eventually reach the node that Metamask uses, reflecting the status of the transaction.

Metamask monitors the status of your transaction. Metamask communicates with its node provider using web3js. web3 allows you to subscribe to events, check the pending transactions (transactions in the mempool), get block headers, check if your transaction is mined and in which block, etc.

Also, if you want to see what would be the result of a transaction, let's say a transaction that calls a smart contract, but you don't want that transaction to be mined, you just want to see what would happen if it was mined, you can use web3.eth.call function. This function sends a transaction to the provider node and the node does not broadcast it, just executes it locally and returns its result, without actually modifying the blockchain (because the transaction is not mined).

To then actually, send your transaction to be mined and broadcasted across the network, use web3.eth.sendTransaction.

You can learn more about web3.eth.call here: https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#call

And about web.eth.sendTransaction here: https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#sendtransaction

2
  • 1
    how do nodes broadcast the transaction to other nodes Aug 16, 2022 at 6:53
  • Each node has a list of other nodes, usually more than 10, but due to space, they cannot "point" to all the nodes in the network. When you first start syncing your node, it starts looking for neighbor nodes. When when it receives a transaction from another node, it sends that transaction to all the nodes it knows, then each of those nodes send the transaction to all the other nodes they know, and so on, until the transaction is fully broadcasted through the network. Aug 16, 2022 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.