Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
751},752},753{"input_weights", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "Inputs and their corresponding weights",754{755{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",756{757{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},758{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output index"},759{"weight", RPCArg::Type::NUM, RPCArg::Optional::NO, "The maximum weight for this input, "760"including the weight of the outpoint and sequence number. "761"Note that serialized signature sizes are not guaranteed to be consistent, "762"so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."763"Remember to convert serialized sizes to weight units when necessary."},764},765},766},767},768{"max_tx_weight", RPCArg::Type::NUM, RPCArg::Default{MAX_STANDARD_TX_WEIGHT}, "The maximum acceptable transaction weight.\n"769"Transaction building will fail if this can not be satisfied."},770},771FundTxDoc()),772RPCArgOptions{773.oneline_description = "options",774}},775{"iswitness", RPCArg::Type::BOOL, RPCArg::DefaultHint{"depends on heuristic tests"}, "Whether the transaction hex is a serialized witness transaction.\n"776"If iswitness is not present, heuristic tests will be used in decoding.\n"777"If true, only witness deserialization will be tried.\n"778"If false, only non-witness deserialization will be tried.\n"779"This boolean should reflect whether the transaction has inputs\n"780"(e.g. fully valid, or on-chain transactions), if known by the caller."781},782},783RPCResult{784RPCResult::Type::OBJ, "", "",785{786{RPCResult::Type::STR_HEX, "hex", "The resulting raw transaction (hex-encoded string)"},787{RPCResult::Type::STR_AMOUNT, "fee", "Fee in " + CURRENCY_UNIT + " the resulting transaction pays"},788{RPCResult::Type::NUM, "changepos", "The position of the added change output, or -1"},789}790},791RPCExamples{792"\nCreate a transaction with no inputs\n"793+ HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") +794"\nAdd sufficient unsigned inputs to meet the output value\n"795+ HelpExampleCli("fundrawtransaction", "\"rawtransactionhex\"") +796"\nSign the transaction\n"797+ HelpExampleCli("signrawtransactionwithwallet", "\"fundedtransactionhex\"") +798"\nSend the transaction\n"799+ HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")800},801[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue802{803std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);804if (!pwallet) return UniValue::VNULL;806// parse hex string from parameter807CMutableTransaction tx;808bool try_witness = request.params[2].isNull() ? true : request.params[2].get_bool();809bool try_no_witness = request.params[2].isNull() ? true : !request.params[2].get_bool();810if (!DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {811throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");812}813UniValue options = request.params[1];814std::vector<std::pair<CTxDestination, CAmount>> destinations;815for (const auto& tx_out : tx.vout) {816CTxDestination dest;817ExtractDestination(tx_out.scriptPubKey, dest);818destinations.emplace_back(dest, tx_out.nValue);819}820std::vector<std::string> dummy(destinations.size(), "dummy");821std::vector<CRecipient> recipients = CreateRecipients(822destinations,823InterpretSubtractFeeFromOutputInstructions(options["subtractFeeFromOutputs"], dummy)824);825CCoinControl coin_control;826// Automatically select (additional) coins. Can be overridden by options.add_inputs.827coin_control.m_allow_other_inputs = true;828// Clear tx.vout since it is not meant to be used now that we are passing outputs directly.829// This sets us up for a future PR to completely remove tx from the function signature in favor of passing inputs directly830tx.vout.clear();831auto txr = FundTransaction(*pwallet, tx, recipients, options, coin_control, /*override_min_fee=*/true);833UniValue result(UniValue::VOBJ);834result.pushKV("hex", EncodeHexTx(*txr.tx));835result.pushKV("fee", ValueFromAmount(txr.fee));836result.pushKV("changepos", txr.change_pos ? (int)*txr.change_pos : -1);838return result;839},840};841}843RPCMethod signrawtransactionwithwallet()844{845return RPCMethod{846"signrawtransactionwithwallet",847"Sign inputs for raw transaction (serialized, hex-encoded).\n"848"The second optional argument (may be null) is an array of previous transaction outputs that\n"849"this transaction depends on but may not yet be in the block chain." +850HELP_REQUIRING_PASSPHRASE,851{852{"hexstring", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction hex string"},853{"prevtxs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "The previous dependent transaction outputs",854{855{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",856{857{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},858{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},859{"scriptPubKey", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The output script"},860{"redeemScript", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "(required for P2SH) redeem script"},861{"witnessScript", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "(required for P2WSH or P2SH-P2WSH) witness script"},862{"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::OMITTED, "(required for Segwit inputs) the amount spent"},863},864},865},866},867{"sighashtype", RPCArg::Type::STR, RPCArg::DefaultHint{"DEFAULT for Taproot, ALL otherwise"}, "The signature hash type. Must be one of\n"868" \"DEFAULT\"\n"869" \"ALL\"\n"870" \"NONE\"\n"871" \"SINGLE\"\n"872" \"ALL|ANYONECANPAY\"\n"873" \"NONE|ANYONECANPAY\"\n"874" \"SINGLE|ANYONECANPAY\""},875},876RPCResult{877RPCResult::Type::OBJ, "", "",878{879{RPCResult::Type::STR_HEX, "hex", "The hex-encoded raw transaction with signature(s)"},880{RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},881{RPCResult::Type::ARR, "errors", /*optional=*/true, "Script verification errors (if there are any)",882{883{RPCResult::Type::OBJ, "", "",884{885{RPCResult::Type::STR_HEX, "txid", "The hash of the referenced, previous transaction"},886{RPCResult::Type::NUM, "vout", "The index of the output to spent and used as input"},887{RPCResult::Type::ARR, "witness", "",888{889{RPCResult::Type::STR_HEX, "witness", ""},890}},891{RPCResult::Type::STR_HEX, "scriptSig", "The hex-encoded signature script"},892{RPCResult::Type::NUM, "sequence", "Script sequence number"},893{RPCResult::Type::STR, "error", "Verification or signing error related to the input"},894}},895}},896}897},898RPCExamples{899HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"")900+ HelpExampleRpc("signrawtransactionwithwallet", "\"myhex\"")901},902[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue903{904const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);905if (!pwallet) return UniValue::VNULL;907CMutableTransaction mtx;908if (!DecodeHexTx(mtx, request.params[0].get_str())) {909throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");910}912// Sign the transaction913LOCK(pwallet->cs_wallet);914EnsureWalletIsUnlocked(*pwallet);916// Fetch previous transactions (inputs):917std::map<COutPoint, Coin> coins;918for (const CTxIn& txin : mtx.vin) {919coins[txin.prevout]; // Create empty map entry keyed by prevout.920}921pwallet->chain().findCoins(coins);923// Parse the prevtxs array924ParsePrevouts(request.params[1], nullptr, coins);926std::optional<int> nHashType = ParseSighashString(request.params[2]);927if (!nHashType) {928nHashType = SIGHASH_DEFAULT;929}931// Script verification errors932std::map<int, bilingual_str> input_errors;934bool complete = pwallet->SignTransaction(mtx, coins, *nHashType, input_errors);935UniValue result(UniValue::VOBJ);936SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);937return result;938},939};940}942// Definition of allowed formats of specifying transaction outputs in943// `bumpfee`, `psbtbumpfee`, `send` and `walletcreatefundedpsbt` RPCs.944static std::vector<RPCArg> OutputsDoc()945{946return947{948{"", RPCArg::Type::OBJ_USER_KEYS, RPCArg::Optional::OMITTED, "",949{950{"address", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "A key-value pair. The key (string) is the bitcoin address,\n"951"the value (float or string) is the amount in " + CURRENCY_UNIT + ""},952},953},954{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",955{956{"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data that becomes a part of an OP_RETURN output"},957},958},959};960}962static RPCMethod bumpfee_helper(std::string method_name)963{964const bool want_psbt = method_name == "psbtbumpfee";965const std::string incremental_fee{CFeeRate(DEFAULT_INCREMENTAL_RELAY_FEE).ToString(FeeRateFormat::SAT_VB)};967return RPCMethod{method_name,968"Bumps the fee of a transaction T, replacing it with a new transaction B.\n"969+ std::string(want_psbt ? "Returns a PSBT instead of creating and signing a new transaction.\n" : "") +970"A transaction with the given txid must be in the wallet.\n"971"The command will pay the additional fee by reducing change outputs or adding inputs when necessary.\n"972"It may add a new change output if one does not already exist.\n"973"All inputs in the original transaction will be included in the replacement transaction.\n"974"The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.\n"975"By default, the new fee will be calculated automatically using the estimatesmartfee RPC.\n"976"The user can specify a confirmation target for estimatesmartfee.\n"977"Alternatively, the user can specify a fee rate in " + CURRENCY_ATOM + "/vB for the new transaction.\n"978"At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee\n"979"returned by getnetworkinfo) to enter the node's mempool.\n"980"* WARNING: before version 0.21, fee_rate was in " + CURRENCY_UNIT + "/kvB. As of 0.21, fee_rate is in " + CURRENCY_ATOM + "/vB. *\n",981{982{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The txid to be bumped"},983{"options", RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "",984Cat(985{986{"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks\n"},987{"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"},988"\nSpecify a fee rate in " + CURRENCY_ATOM + "/vB instead of relying on the built-in fee estimator.\n"989"Must be at least " + incremental_fee + " higher than the current transaction fee rate.\n"990"WARNING: before version 0.21, fee_rate was in " + CURRENCY_UNIT + "/kvB. As of 0.21, fee_rate is in " + CURRENCY_ATOM + "/vB.\n"},991{"replaceable", RPCArg::Type::BOOL, RPCArg::Default{true},992"Whether the new transaction should be\n"993"marked bip-125 replaceable. If true, the sequence numbers in the transaction will\n"994"be set to 0xfffffffd. If false, any input sequence numbers in the\n"995"transaction will be set to 0xfffffffe\n"996"so the new transaction will not be explicitly bip-125 replaceable (though it may\n"997"still be replaceable in practice, for example if it has unconfirmed ancestors which\n"998"are replaceable).\n"},999{"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"unset"}, "The fee estimate mode, must be one of (case insensitive):\n"1000+ FeeModesDetail(std::string("economical mode is used if the transaction is replaceable;\notherwise, conservative mode is used"))},