githubEdit

createrawtransaction - Bitcoin

Example code for the createrawtransaction JSON RPC method. Сomplete guide on how to use createrawtransaction JSON RPC in GetBlock Web3 documentation.

createrawtransaction - Bitcoin

Example code for the createrawtransaction JSON-RPC method. Complete guide on how to use createrawtransaction JSON-RPC in GetBlock Web3 documentation.

This method creates a raw transaction, spending the given inputs and creating new outputs. The transaction is unsigned and must be signed before it can be broadcast.

Parameters

Parameter
Type
Required
Description

inputs

array

Yes

Array of input objects specifying UTXOs to spend.

inputs[].txid

string

Yes

The transaction id of the UTXO to spend.

inputs[].vout

number

Yes

The output index of the UTXO to spend.

inputs[].sequence

number

No

The sequence number (default: depends on locktime).

outputs

array

Yes

Array of output objects mapping addresses to amounts or data.

locktime

number

No

Raw locktime. Non-0 value also activates inputs (default: 0).

replaceable

boolean

No

Marks this transaction as BIP125-replaceable (default: true).

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "createrawtransaction",
    "params": [
        [{"txid": "ee652f0b40209bd02468de0c6336854f5efdd79fb865560aef2c46f4fa0b4a07", "vout": 0}],
        [ {
                "data": "00010203"
            }]
    ],
    "id": "getblock.io"
}'

Response

Response Parameters

Field
Type
Description

result

string

The hex-encoded unsigned raw transaction.

Use Case

The createrawtransaction method is essential for:

  • Building custom transactions with precise control

  • Creating unsigned transactions for offline signing

  • Constructing time-locked transactions

  • Building OP_RETURN data transactions

  • Implementing payment batching

  • Creating replace-by-fee (RBF) transactions

Error Handling

Status Code
Error Message
Cause

403

RBAC: access denied

Missing or invalid ACCESS-TOKEN.

-5

Invalid Bitcoin address

One of the output addresses is invalid.

-3

Invalid amount

Amount is out of range or has too many decimals.

Integration Notes

The createrawtransaction method helps developers:

  • Build transactions with complete control over inputs/outputs

  • Implement custom UTXO selection algorithms

  • Create transactions with embedded data (OP_RETURN)

  • Support legacy signing workflows

  • Build advanced payment protocols

Last updated

Was this helpful?