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

Select a set of coins such that nTargetValue is met&semi; never select unconfirmed coins if they are not ours

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
&lsqb;&lsqb;requires&lowbar;capability(0x7f94fdec3398)&rsqb;&rsqb;
xref:util/Result.adoc[util::Result&lt;SelectionResult&gt;]
AutomaticCoinSelection(
    xref:wallet/CWallet.adoc[CWallet] const& wallet,
    xref:wallet/CoinsResult.adoc[CoinsResult]& available&lowbar;coins,
    xref:CAmount.adoc[CAmount] const& nTargetValue,
    xref:wallet/CoinSelectionParams.adoc[CoinSelectionParams] const& coin&lowbar;selection&lowbar;params);
----

== Return Value

If successful, a SelectionResult containing the selected coins If failed, returns (1) an empty error message if the target was not reached (general &quot;Insufficient funds&quot;) or (2) an specific error message if there was something particularly wrong (e&period;g&period; a selection result that surpassed the tx max weight size)&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *wallet* [in]
| The wallet which provides data necessary to spend the selected coins
| *available&lowbar;coins* [in]
| The struct of coins, organized by OutputType, available for selection prior to filtering
| *nTargetValue* [in]
| The target value
| *coin&lowbar;selection&lowbar;params* [in]
| Parameters for this coin selection such as feerates, whether to avoid partial spends, and whether to subtract the fee from the outputs&period;
|===


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