Quick Start
Submit Your First Transaction
Submit Bitcoin transaction
3min
creating a bitcoin transaction using bitcoin cli and maestro apis this guide covers the steps to create a bitcoin transaction using bitcoin cli on testnet4 blockchain and maestro apis we will generate a testnet4 bitcoin address, transfer funds to our address, create a raw transaction, calculate fees using maestro api, sign the transaction, and broadcast it to the bitcoin network via maestro api prerequisites a running bitcoin core node with bitcoin cli access see setup bitcoin node guide in order to run a testnet4 bitcoin node and install bitcoin cli maestro api credentials for retrieving transaction fees and broadcasting transactions see getting started guide in order to create a free maestro account submit a bitcoin transaction step 1 create a new wallet and generate a new bitcoin address to receive bitcoin, first, you will need to create a new wallet and then generate a new address using bitcoin cli open cmd on windows or terminal on linux and navigate to the bitcoin daemon folder and run the commands below #let's create a new bitcoin wallet \>bitcoin cli testnet4 createwallet "maestrowallet1" #now you can create a new address that will be associated with your wallet \>bitcoin cli testnet4 getnewaddress "address1" mwb5sqzymfqj1bqxpttl8w2brmr6ehfeem the first command returns a newly generated bitcoin wallet the second command creates a new address in that wallet which you can use as the recipient or sender in transactions step 2 get tbtc or test bitcoin (utxos) to create a bitcoin transaction, our wallet must have funds stored as utxos (unspent transaction outputs) we'll receive test bitcoin (tbtc) from the testnet4 faucet to address1 this test bitcoin (not real btc) will be used as utxo to send funds to another address on the testnet4 blockchain go to coinfaucet website and enter your bitcoin testnet4 address in order to receive test bitcoin maestro get tbtc to bitcoin testnet address the coin faucet will send test bitcoin (tbtc) to our address1 testnet4 wallet, generating a transaction (tx) that will be recorded on the bitcoin testnet4 blockchain abe3318569c84d229dd8aea53ca8e7c9dfe725d2f866ee60a8926cbfba4ddc0c maestro bitcoin explorer you can lookup the transaction by visiting explorer gomaestro org and entering the transaction id (txid) https //explorer gomaestro org/bitcoin/testnet/transactions/abe3318569c84d229dd8aea53ca8e7c9dfe725d2f866ee60a8926cbfba4ddc0c https //explorer gomaestro org/bitcoin/testnet/transactions/abe3318569c84d229dd8aea53ca8e7c9dfe725d2f866ee60a8926cbfba4ddc0c https //explorer gomaestro org/bitcoin/testnet/transactions/abe3318569c84d229dd8aea53ca8e7c9dfe725d2f866ee60a8926cbfba4ddc0c step 3 get unspent transaction outputs (utxos) in step 2, we received 0 0001776 tbtc the bitcoin faucet generated a transaction with two utxo outputs one of these utxos was assigned to our address as an output of that transaction, making it available as an input for future transactions refer to the screenshot below in order to get all unspent transaction outputs (utxos) in your address use maestro's api curl location ' https //xbt testnet gomaestro api org/v0/addresses/mwb5sqzymfqj1bqxpttl8w2brmr6ehfeem/utxos?api key={your maestro api key} https //xbt testnet gomaestro api org/v0/addresses/mwb5sqzymfqj1bqxpttl8w2brmr6ehfeem/utxos?api key={your maestro api key} ' below is the output for the maestro api request utxos by address maestro api get unspent utxos by address in the given utxo (unspent transaction output) data txid (transaction id) a unique identifier for the bitcoin transaction that created this utxo "txid" "a4b80f03ff283418825ef8b30e4d2668fc8f61295f6dd2f95ac46074f704b1fb" vout (output index) the index of this specific output in the transaction a bitcoin transaction can have multiple outputs, and vout specifies which output is being referenced "vout" 1 means this is the second output (indexes start at 0) together, txid and vout uniquely identify a utxo, which can be spent in a future transaction each transaction creates outputs each bitcoin transaction can create multiple outputs the vout index refers to the specific output within that transaction "txid" "a4b80f03ff28 " has an output at vout 1 "txid" "0a35bebbd903 " also has an output at vout 1 these are separate transactions, meaning each txid corresponds to a different transaction, but both have at least two outputs (one at index 0 and another at index 1) in our case each utxo comes from a different transaction even though both utxos belong to the same address (mwb5sqzymfqj1bqxpttl8w2brmr6ehfeem), they originate from separate transactions, making their combination of txid and vout unique in the screenshot below we can witness that "txid" "0a35bebbd903 " has two outputs and one of them, with the vout 1 for that transaction, was an input utxo to our address similarly, the transaction with txid "0a35bebbd903 " has two outputs one of them, with index vout 1 , became an input utxo for our address when funds were spent in a new transaction the remaining change from the transaction was sent back to our address refer to the screenshot below why this matters when spending a utxo in a new transaction, you must reference its exact txid and vout since each txid is different, these are two separate utxos , even though both have vout 1 this returns a list of utxos available for spending identify the utxo’s txid and vout to use in the next step step 4 create a second bitcoin testnet address let' generate a second address on bitcoin testnet blockchain and create utxo to send tbtc from address1 to address2 >bitcoin cli testnet4 getnewaddress "address2" mxvhxyqgxyaj1zfuwba7qguyh97obnynka maestro generate bitcoin address utxo let's create a raw transaction using bitcoin cli command step 5 create a raw transaction use the utxo details to create a raw transaction replace placeholders with actual values >bitcoin cli createrawtransaction '\[{"txid" "utxo txid","vout" 1 n}]' '{"recipient address"\ amount,"change address"\ amount}' utxo txid the transaction id of the unspent output utxo vout the output index of the utxo recipient address the address receiving bitcoin amount the amount (in btc) to send change address your change address for receiving remaining funds change amount the remaining balance after subtracting the transaction fee this command constructs a raw bitcoin transaction, using a specific utxo as an input and defining two output addresses with specified amounts the generated raw transaction must be signed and broadcasted to the network to take effect >bitcoin cli createrawtransaction '\[{"txid" "0a35bebbd903c6b0963eaeae5abcbe9ab57d80aafb3b24ccf1e6073672abde73", "vout" 1 }]' '{"mxvhxyqgxyaj1zfuwba7qguyh97obnynka" 0 00015206, "mwb5sqzymfqj1bqxpttl8w2brmr6ehfeem" 0 00001}' createrawtransaction– creates a raw bitcoin transaction without signing or broadcasting it first argument (\[{"txid" " ","vout" 1 }])– specifies the transaction input txid is the transaction id from which the utxo is being spent vout specifies the output index (1 in this case) from the previous transaction, meaning we are using the second output as an input second argument ({"mxvhxyqgxyaj1zfuwba7qguyh97obnynka" 0 00015206, "mwb5sqzymfqj1bqxpttl8w2brmr6ehfeem" 0 00001})– defines the outputs sends 0 00015206 tbtc to address mxvhxyqgxyaj1zfuwba7qguyh97obnynka sends 0 00001 tbtc to address mwb5sqzymfqj1bqxpttl8w2brmr6ehfeem maestro create a bitcoin raw transaction step 6 calculate transaction fee using maestro maestro has two apis that you can use to calculate estimated fees and the minimum, median, and maximum fee rates for a transaction to be verified on a block use maestro's api to get the recommended fee rate curl location ' https //xbt testnet gomaestro api org/v0/rpc/transaction/estimatefee/6 https //xbt testnet gomaestro api org/v0/rpc/transaction/estimatefee/6 ' \ header 'api key {maestro api key}' this api returns an estimate fee rate for 6 transaction verifications select a fee rate and adjust the change amount accordingly see mempool block fee rates maestro api documentation use maestro mempool api to calculate min, median and max block fee rates per tx https //xbt testnet gomaestro api org/v0/mempool/fee rates https //xbt testnet gomaestro api org/v0/mempool/fee rates curl location ' https //xbt testnet gomaestro api org/v0/mempool/fee rates https //xbt testnet gomaestro api org/v0/mempool/fee rates ' \ header 'api key {your maestro enterprise api key}' this api returns fee rates for different speeds (low, medium, high) select a fee rate and adjust the change amount accordingly see mempool block fee rates maestro api documentation this section contains information related to the block and its fee estimates "data" \[] block height the height (or index) of the block on the blockchain in this case, it's block number 70608 sats per vb (satoshis per virtual byte)this shows the estimated fee rate in (sats/vbyte), which is used for calculating transaction fees " i ndexer info" {} chain tipthe latest block in the blockchain that is known by the indexer it provides the block hash and the block height of the latest confirmed block block hashthe hash of the latest block in the chain block heightthe height of the latest block in the blockchain mempool timestampthe timestamp of when the data related to the mempool was recorded the mempool holds unconfirmed transactions waiting to be included in a block estimated blocksthe predicted next block and its fee structure step 7 sign the transaction >bitcoin cli signrawtransactionwithwallet "raw tx hex" this command returns a signed transaction (hex) ready for broadcasting step 8 verify the signed transaction to check if the transaction is valid before broadcasting run the command below >bitcoin cli testmempoolaccept '\["signed tx hex"]' if the command is valid and you provide a valid signed transaction (signed tx hex), it will return a json response where you can find the key value pair "allowed"\ true indicating whether the transaction would be accepted into the mempool or not step 9 broadcast the transaction using maestro api use maestro’s api to push the transaction to the bitcoin network curl location ' https //xbt testnet gomaestro api org/v0/rpc/transaction/submit https //xbt testnet gomaestro api org/v0/rpc/transaction/submit ' \ header 'content type text/plain' \ header 'api key {your maestro api key}' \ data '"02000000010a336d7554da8b351850e57712379081364520309bd0fdb0c410ca4e3f8161c5010000006a47304402203c4fd342c1e8a8047ae1f5cd3c91bfed07328bc22d456f3db24a23c1769f51c40220523bed0042446df1830b44fe4ded71c6085a6e0bc389b2635abb3c4b385eff6f012102bfdbc8b5243526c89c31da25b9669121a7c98a4ba44a5c7d3a79fb0d58ea5e7bfdffffff02a03d0000000000001976a9140a5f580e3773f79eb266c9553c4f8187675bec9b88ace8030000000000001976a914861ba3640bb054ab203c13222fda0c2b58c3471788ac00000000"' if successful, the response includes the transaction id use maestro bitcoin explorer to monitor the transaction step 10 monitor the transaction in the mempool using maestro use mempool utxo by address api in order to monitor the broadcasted transaction curl location ' https //xbt testnet gomaestro api org/v0/mempool/addresses/mxvhxyqgxyaj1zfuwba7qguyh97obnynka/utxos https //xbt testnet gomaestro api org/v0/mempool/addresses/mxvhxyqgxyaj1zfuwba7qguyh97obnynka/utxos ' \ header 'api key {your maestro enterprise api key}' to see the transaction on the testnet4 blockchain use mempool space/testnet4 step 11 monitor transaction onchain using maestro apis transactions by address maestro api curl location ' https //xbt testnet gomaestro api org/v0/addresses/mgtogb1sxhdbipbhe5tgmqyuck1dnejxqa/txs https //xbt testnet gomaestro api org/v0/addresses/mgtogb1sxhdbipbhe5tgmqyuck1dnejxqa/txs ' \ header 'api key {your maestro api key}' transaction info maestro api congrats! you made it to this point and now you know how to create a bitcoin transaction using maestro apis next topic > how to create a cardano transaction