[#wallet-CreateTransaction]
= xref:wallet.adoc[wallet]::CreateTransaction
:relfileprefix: ../
:mrdocs:

Create a new transaction paying the recipients with a set of coins selected by SelectCoins()&semi; Also create the change output, when needed

== Synopsis

Declared in `&lt;wallet&sol;spend&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:util/Result.adoc[util::Result&lt;CreatedTransactionResult&gt;]
CreateTransaction(
    xref:wallet/CWallet.adoc[CWallet]& wallet,
    std::vector&lt;CRecipient&gt; const& vecSend,
    std::optional&lt;unsigned int&gt; change&lowbar;pos,
    xref:wallet/CCoinControl.adoc[CCoinControl] const& coin&lowbar;control,
    bool sign = true);
----

== Description

[NOTE]
====
passing change&lowbar;pos as std&colon;&colon;nullopt will result in setting a random position

====

== Return Value

If successful, the created transaction and its fee details, otherwise an error&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *wallet*
| The wallet funding and optionally signing the transaction&period;
| *vecSend*
| The recipients and amounts to pay&period;
| *change&lowbar;pos*
| The position of the change output, or std&colon;&colon;nullopt for a random position&period;
| *coin&lowbar;control*
| Coin control settings governing input selection and fees&period;
| *sign*
| Whether to sign the created transaction&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
