[#node-BroadcastTransaction]
= xref:node.adoc[node]::BroadcastTransaction
:relfileprefix: ../
:mrdocs:

Submit a transaction to the mempool and (optionally) relay it to all P2P peers&period;

== Synopsis

Declared in `&lt;node&sol;transaction&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
xref:node/TransactionError.adoc[TransactionError]
BroadcastTransaction(
    xref:node/NodeContext.adoc[NodeContext]& node,
    xref:CTransactionRef.adoc[CTransactionRef] tx,
    std::string& err&lowbar;string,
    xref:CAmount.adoc[CAmount] const& max&lowbar;tx&lowbar;fee,
    xref:node/TxBroadcast.adoc[TxBroadcast] broadcast&lowbar;method,
    bool wait&lowbar;callback);
----

== Description

Mempool submission can be synchronous (will await mempool entry notification over the CValidationInterface) or asynchronous (will submit and not wait for notification), depending on the value of wait&lowbar;callback&period; wait&lowbar;callback MUST NOT be set while cs&lowbar;main, cs&lowbar;mempool or cs&lowbar;wallet are held to avoid deadlock&period;

== Return Value

TransactionError&colon;&colon;OK on success, or an error code describing why submission or broadcast failed&period;

[NOTE]
====
The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^].
====
== Parameters

[cols="1,4"]
|===
| Name| Description
| *node* [in]
| reference to node context
| *tx* [in]
| the transaction to broadcast
| *err&lowbar;string* [out]
| reference to std&colon;&colon;string to fill with error string if available
| *max&lowbar;tx&lowbar;fee* [in]
| reject txs with fees higher than this (if 0, accept any fee)
| *broadcast&lowbar;method* [in]
| whether to add the transaction to the mempool and how to broadcast it
| *wait&lowbar;callback* [in]
| wait until callbacks have been processed to avoid stale result due to a sequentially RPC&period;
|===


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