BitcoinMethods

fundrawtransaction

The fundrawtransaction method is used to add inputs to a transaction until it has enough in value to meet its out value. If the transaction initially has no inputs, they will be automatically selec...

fundrawtransaction

Overview

The 'fundrawtransaction' method is used to add inputs to a transaction until it has enough in value to meet its out value. If the transaction initially has no inputs, they will be automatically selected. This method can add at most one change output to the outputs and won't modify existing outputs unless specified by the "subtractFeeFromOutputs" option. Note that inputs which were signed may need to be resigned after the completion since in/outputs have been added. The added inputs will not be signed; use methods like 'signrawtransactionwithkey' or 'signrawtransactionwithwallet' for that.

Request

shell

wget --no-check-certificate --quiet \
  --method POST \
  --timeout=0 \
  --header 'Content-Type: application/json' \
  --header 'accept: application/json' \
  --header 'X-CoinAPI-Key: 4303fb63-adec-42dc-b571-74bc2f2a5167' \
  --body-data '{"jsonrpc":"2.0","id":1,"method":"fundrawtransaction","params": [ ]}
' \
   'https://bitcoin-mainnet.node.coinapi.io'

csharp

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://bitcoin-mainnet.node.coinapi.io");
request.Headers.Add("accept", "application/json");
request.Headers.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY");
var content = new StringContent("{\r\n  \"jsonrpc\": \"1.0\",\r\n  \"id\": \"1\",\r\n  \"method\": \"fundrawtransaction\",\r\n  \"params\": []\r\n}\r\n", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

php

<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json',
  'accept' => 'application/json',
  'X-CoinAPI-Key' => '73034021-THIS-IS-SAMPLE-KEY'
];
$body = '{
  "jsonrpc": "1.0",
  "id": "1",
  "method": "fundrawtransaction",
  "params": []
}';
$request = new Request('POST', 'https://bitcoin-mainnet.node.coinapi.io', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
?>

python

import requests
import json

url = "https://bitcoin-mainnet.node.coinapi.io"

payload = json.dumps({
  "jsonrpc": "2.0",
  "method": "fundrawtransaction",
  "params": [
    "0x4c253746668dca6ac3f7b9bc18248b558a95b5fc881d140872c2dff984d344a7"
  ],
  "id": 1
})
headers = {
  'x-coinapi-key': '73034021-THIS-IS-SAMPLE-KEY',
  'Content-Type': 'application/json',
  'accept': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

javascript

var settings = {
  "url": "https://bitcoin-mainnet.node.coinapi.io",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "x-coinapi-key": "73034021-THIS-IS-SAMPLE-KEY",
    "Content-Type": "application/json",
    "accept": "application/json"
  },
  "data": JSON.stringify({
    "jsonrpc": "2.0",
    "method": "fundrawtransaction",
    "params": [
      "0x4c253746668dca6ac3f7b9bc18248b558a95b5fc881d140872c2dff984d344a7"
    ],
    "id": 1
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

go

package main

package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

url := "https://bitcoin-mainnet.node.coinapi.io"
method := "POST"

payload := strings.NewReader(`{`+"
"+`
  "jsonrpc": "1.0",`+"
"+`
  "id": "1",`+"
"+`
  "method": "fundrawtransaction",`+"
"+`
  "params": []`+"
"+`
}`+"
"+`
`)

client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)

if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("accept", "application/json")
req.Header.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")

res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

ruby

require "uri"
require "json"
require "net/http"

url = URI("https://bitcoin-mainnet.node.coinapi.io")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["accept"] = "application/json"
request["X-CoinAPI-Key"] = "73034021-THIS-IS-SAMPLE-KEY"
request.body = JSON.dump({
"jsonrpc": "1.0",
"id": "1",
"method": "fundrawtransaction",
"params": []
})

response = https.request(request)
puts response.read_body

java

OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n  \"jsonrpc\": \"1.0\",\r\n  \"id\": \"1\",\r\n  \"method\": \"fundrawtransaction\",\r\n  \"params\": []\r\n}\r\n");
Request request = new Request.Builder()
  .url("https://bitcoin-mainnet.node.coinapi.io")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("accept", "application/json")
  .addHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
  .build();
Response response = client.newCall(request).execute();

Request Parameters

  • hexstring (string, required): The hex string of the raw transaction.
  • options (json object, optional): Additional options for the transaction. Can include fields like "replaceable", "conf_target", and "estimate_mode".
  • iswitness (boolean, optional): Specifies whether the transaction hex is a serialized witness transaction. The default value depends on heuristic tests performed during decoding.

Response

  • psbt (string): The base64-encoded partially signed transaction if not extracted.
  • hex (string): The hex-encoded network transaction if extracted.
  • complete (boolean): Indicates if the transaction has a complete set of signatures.
Service StatusGitHub SDK