Is there a way to create coinbase transactions with an RPC command? Is there a way to create coinbase transactions with an RPC command?
Yep, it is partially possible with the getblocktemplate RPC command.

This is what miners routinely use to obtain the information necessary to begin mining a block.
The exact parameters and response has been specified by BIP 22 and BIP 23 (an extension for pooled mining).

These output values will provide the information you need:

"coinbaseaux" : {                 (json object) data that should be included in the coinbase's scriptSig content
      "flags" : "xx"                  (string) key name is to be ignored, and value included in scriptSig
  },
  "coinbasevalue" : n,              (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis)
  "coinbasetxn" : { ... },          (json object) information for coinbase transaction


Unfortunately, although specified, it does not appear that Bitcoin core provides the "coinbasetxn" JSON object for you, so you'll have to create it manually. However, this will at minimum give you the coinbase value and transactions to include in the block.

You can create the coinbase transactions just like any other transaction, however it MUST abide by the following rules:


BIP 34 which requires you to prefix the input script with the serialized height of the block.


For example, the input script of block 549,322 is:

------ Original ------
03CA6108FABE6D6D15B0663A60E46473FBA0C15DBEDCC466A5B71C741D9FFE721E38E9D161BCE45201000000000000000C65070100FB9B000013D7EC00082F736C7573682F

------ Decoded ------
03 -&gt; Push 3 bytes
CA6108F -&gt; 549,322 (height in littleEndian)
------ Remaining data is arbitrary ------
ABE6D6D15B0663A60E46473FBA0C15DBEDCC466A5B71C741D9FFE721E38E9D161BCE45201000000000000000C65070100FB9B000013D7EC00082F736C7573682F



Must have one TX input
Previous hash =  0x0000000000000000000000000000000000000000000000000000000000000000 (since coinbase is the first TX in a block)
Previous output n = 0xFFFFFFFF (-1 decimal since coinbase is the 0th transaction)
Output does not exceed (block reward + fees) or the coinbasevalue if you're using the RPC command with the provided transactions.


In our example block (549,332), the coinbase transaction's raw hexadecimal (the output found in createrawtransaction RPC command) is:

010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff4503ca6108fabe6d6d15b0663a60e46473fba0c15dbedcc466a5b71c741d9ffe721e38e9d161bce45201000000000000000c65070100fb9b000013d7ec00082f736c7573682f0000000003b33eee4a000000001976a9147c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac00000000000000002c6a4c2952534b424c4f434b3a8cca119e75a4d70a57346f0fb9facc55f00f150265095a92ca27a9b1b1ac6e000000000000000000266a24aa21a9edb8c0253a8b72023513b3f8c08591fb009e1b89d1651ee044d183a4c627399a710120000000000000000000000000000000000000000000000000000000000000000000000000


which decodes to:

01000000 -&gt; txVersion
00 -&gt; SegWit marker
01 -&gt; SegWit flag
01 -&gt; Input count (important that it is 1 for coinbase transactions!)
0000000000000000000000000000000000000000000000000000000000000000 -&gt; Previous hash
ffffffff -&gt; Previous output #
45 -&gt; input script length
  03 -&gt; Push 3 bytes
  ca6108 -&gt; block height (littleEndian)
  -- arbitrary data --
  fabe6d6d15b0663a60e46473fba0c15dbedcc466a5b71c741d9ffe721e38e9d161bce45201000000000000000c65070100fb9b000013d7ec00082f736c7573682f
00000000 -&gt; sequence
03 -&gt; output count
  b33eee4a00000000 -&gt; output 1 value
  19 -&gt; output 1 script length
  76a9147c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac -&gt; Pay-to-Public-Key-Hash script

  0000000000000000 -&gt; output 2 value
  2c -&gt; output 2 script length
  6a4c2952534b424c4f434b3a8cca119e75a4d70a57346f0fb9facc55f00f150265095a92ca27a9b1b1ac6e00 -&gt; provably unspendable

  0000000000000000 -&gt; output 3 value (witness commitment)
  26 -&gt; output 3 length
  6a24aa21a9edb8c0253a8b72023513b3f8c08591fb009e1b89d1651ee044d183a4c627399a71

01 -&gt; number of witnesses
20 -&gt; witness length
0000000000000000000000000000000000000000000000000000000000000000 -&gt; witness
00000000 -&gt; locktime


For more information on how to actually utilize createrawtransaction with these values, see this and this.