1

My question has already been asked before, and some answers were also already given the question, however, it's not clear to me why I get some behaviour when implementing it. Here are the details:

I created my transaction and signed it offline, without interacting with bitcoind. But, when I broadcast it to the network (or test acceptability by mempool), it doesn't work unless I import the private key to bitcoind through the rpc command importprivkey.

I inspected the bitcoin code to understand why it does behave like that, but unfortunately, I don't quite understand where it does verify for the private key or check that it was imported. As I understand, the transaction's broadcast happens here sendrawtransaction.

Please, can someone explain why it does happen and/or provide a way to just broadcast raw transactions to the network without importing private keys into bitcoind?

2
  • 2
    This is very strange; sendrawtransaction is a node RPC and importprivkey is a wallet RPC; the two should be completely unrelated, and there is absolutely no requirement that a transaction's private key(s) are imported in order to broadcast a transaction or get it accepted to the mempool. Can you update your post with detailed steps to reproduce the problem? Oct 30, 2023 at 12:12
  • I think you are right. It didn't work because I was checking that the utxos were spendable before adding them to the transactions. After reading you, I realise that you should be right. Oct 30, 2023 at 12:38

1 Answer 1

2

The described behavior does not make sense to me. The sendrawtransaction is a node RPC that takes a raw transaction and submits it to the local node’s mempool. If the transaction makes it into the local node’s mempool, the node will relay it to its peers. To that end, the transaction must already be complete. The RPC will work for any valid transaction and does not even require a wallet to be active on the node. Since you could even rebroadcast foreign transactions that way, it seems implausible that the sendrawtransaction call would interact with private keys in any way whatsoever.

1
  • 2
    Yes, in fact, I got this behaviour because I was only considering the utxos that were spendable. Something like if utxo['spendable'] then add it to outputs. It follows that it was the wrong thing to do since the outputs will be empty if the wallet doesn't have the private keys. Oct 30, 2023 at 14:22

Your Answer

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

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