Let's say the user sends me his private key. What is the appropriate RPC command to spend the Bitcoins of this user using his private key?
Should I import his private key in the wallet before?
Let's say the user sends me his private key. What is the appropriate RPC command to spend the Bitcoins of this user using his private key?
Should I import his private key in the wallet before?
If you're using Bitcoin Core, you must first import the private key using the importprivkey
console command. The coins held by that private key will then be added to your existing balance (if any).
If you want to spend those specific coins rather than some others in your wallet, you can use the "coin control" feature. This can be enabled in Settings:Options:Display; when you send coins, you will be offered a list to select which addresses/transactions you want to spend from.
For RPC you can do a raw transaction where you can specify which inputs to use. First listunspent then createrawtransaction, then sign and transmit to the network.