51 votes
Accepted

Redeeming a raw transaction step by step example required

Step-by-step description: We start creating a new transaction which we hash and sign. Add four-byte version field: 01000000 One-byte varint specifying the number of inputs: 01 32-byte hash of the ...
user avatar
  • 6,622
50 votes
Accepted

My raw transaction destroyed 0.0284377 BTC. What did I do wrong?

Addresses that start with 3... are P2SH addresses, and they've been around for almost 6 years now. Historically they saw limited use - used by multisig wallets like Copay and GreenAddress. The ...
user avatar
19 votes
Accepted

How to sign a transaction with multiple inputs?

I found the way to do it, so, if anyone is interested, here is how to do it: When you have more than 1 input, you don't have to remove the inputs that you are not going to sign, you have to remove ...
user avatar
14 votes

Is it possible to create a transaction in pure python without needing to run bitcoin locally?

In case you have not seen it, there is a good (IMHO) article which describes how to generate a transaction "manually" using "raw" python (no bitcoin libs or RPC): "Bitcoins the hard way: Using the ...
user avatar
  • 241
11 votes

How does the variable length integer work?

From the Bitcoin forum: The way the variable length integer works is: Look at the first byte If that first byte is less than 253, use the byte literally If that first byte is 253, read ...
user avatar
  • 191
11 votes
Accepted

What does a segregated witness transaction look like?

From Bitcoin Core's primitive/transaction.h: /** * Basic transaction serialization format: * - int32_t nVersion * - std::vector<CTxIn> vin * - std::vector<CTxOut> vout * - uint32_t ...
user avatar
10 votes

Create OP_RETURN tx with Bitcoinjs-lib

Here: var bitcoin = require('bitcoinjs-lib') data = new Buffer("Melons.") var tx = new bitcoin.TransactionBuilder() tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31", 0)...
user avatar
  • 28.7k
9 votes

Is it possible to create a transaction in pure python without needing to run bitcoin locally?

Vitalik Buterin has recently shared Pybitcointools, a nice and simple-to-use Python library for handcrafting Bitcoin transactions. The example shows the basic workflow, which is pretty much what you ...
user avatar
  • 1,394
9 votes
Accepted

How to tell which part of the previous tx I need to make the hash to sign for an old given tx?

Disclaimer: I am going to assume that you are not completely clueless and that you know what an array is, how to count from 0, and how to match brackets, quotes, and colons so that you can read JSON ...
user avatar
  • 61.5k
8 votes
Accepted

How do you spend a P2SH transaction?

You get this error because Bitcoin has tried to validate the script, and failed, because not all of the signatures necessary were added in the previous signrawtransaction. You can also tell this ...
user avatar
  • 28.7k
8 votes
Accepted

Is it possible to combine two separate transactions into one transaction by only using their signatures?

The only possibility in Bitcoin today is the one described by kaykurokawa. Every signature specifies which inputs and outputs it signs for, so if you want independently-created signatures, it will be ...
user avatar
8 votes
Accepted

What are the hex and asm field values in the JSON decoded from a raw transactions?

asm refers to the de-serialised form of the script, with well-known tokens parsed as script tokens. hex is just the serialised form of the script in hex encoding. If you compare them carefully, ...
user avatar
  • 2,378
8 votes
Accepted

Breaking down a raw transaction:

The bolded byte in the following raw transaction is the number of outputs (two in this transaction): ...
user avatar
7 votes
Accepted

Transaction with OP_RETURN rejected by bitcoind 0.9

I suspect that the second output is being rejected because it contains an OP_RETURN with two data pushes. From browsing the code, "Solver" in script.cpp only categorizes output scripts as "standard" ...
user avatar
7 votes
Accepted

How to sign raw transaction given a private key and SHA hash (in java)

This answer does not attempt to sign a transaction, but simply focuses on successfully calling the sign method of the ECKey class, i.e. making your code work. I am not yet familiar with the ...
user avatar
7 votes

what's the point of "n" in "vout"? getrawtransaction

The vout index (n) that you see after calling decoderawtransaction is added by bitcoind. It is not present in the raw transaction data. If you manually decode the serialized tx for your example, you ...
user avatar
  • 16.5k
7 votes
Accepted

what's the point of "n" in "vout"? getrawtransaction

Since it's an array, couldn't you just use the array index? Seems redundant, but i'm sure there's a reason. Thanks Yes, you could. In fact, that is how n is calculated since it isn't actually stored ...
user avatar
  • 61.5k
6 votes
Accepted

Signing a raw transaction with Python ECDSA (or OpenSSL)

OK, I figured out how to sign the raw Tx using Python ecdsa. I'll step through it: Recall: createrawtransaction '[{"txid" : "72b764383b99fb3d112ac8b474a5d7c4242b75dbfee2d4e9cf9a6703d90f805a", "vout" ...
user avatar
6 votes

How to decode raw tx hex programmatically

This is specified thoroughly on the Bitcoin Wiki. The first 4 bytes are the version number, the next 1-9 bytes are the number of inputs (almost never more than 1 byte) and so on. Programitically, ...
user avatar
  • 7,639
6 votes

Is it possible to combine two separate transactions into one transaction by only using their signatures?

Yes. But they require the transaction to be signed a certain way. OP_CHECKSIG has settable flags, which determines which of the inputs and outputs are signed. If SIGHASH_SINGLE and ...
user avatar
  • 2,052
6 votes
Accepted

How do I spend bitcoins from multiple wallets in a single transaction?

There are currently three different ways to do this: raw transactions, PSBT in 0.17, and PSBT in 0.18. I recommend that you use PSBT in 0.18 as it is the least hassle, but I will describe all three ...
user avatar
  • 61.5k
6 votes

How would this normal raw transaction appear if it was a raw segwit transaction?

wow, cool question, that's not very easy. Especially as there are different Segwit tx thinkable (native P2WPKH, P2SH-P2WPKH, Native P2WSH, P2SH-P2WSH or one with Bech32 address). Then there is the ...
user avatar
  • 5,006
6 votes

How to extract addresses from input in raw transaction

Addresses are associated with output scripts (scriptPubKeys). This information is not encoded in the transaction, the only information in the input is the txid and index of the output that is being ...
user avatar
  • 3,185
6 votes
Accepted

Can I send almost 1MB transaction?

Can I send almost 1MB transaction? To be able to send a transaction that a miner will accept, that transaction has to be a standard transaction. As defined in policy.h /** The maximum weight for ...
user avatar
  • 9,819
6 votes
Accepted

Function combinerawtransaction is not working

The issue here is that the two transactions are different, and combinerawtransaction does not operate on different transactions (it apparently just silently does nothing). It sounds like you expect ...
user avatar
  • 61.5k
5 votes
Accepted

Transaction's maximum size

There is a maximum standard transaction size since Bitcoin 0.8.2 of 100k per transaction. There are a number of other limits that influence the validation and propagation of a transaction though. ...
user avatar
  • 886
5 votes
Accepted

What is the "sequence" and its details as referenced for the segwit application?

Sequence is part of any input, before segwit as well. feffffff is the hexadecimal number 0xfffffffe because the bytes need to be reversed. This sequence number, as per BIP 125, is because: Wallets ...
user avatar
  • 11.3k
5 votes
Accepted

How to decode raw transaction which has 00 in '#TxIn' slot?

This is a SegWit transaction, serialized using the new format defined in BIP144. The format is only permitted when at least one of the transaction inputs has a witness, and works as follows: 4-byte ...
user avatar
5 votes
Accepted

Raw transactions - SubtractFeeFromAmount flag

When you create a raw transaction, you must specify all inputs and outputs, and any leftover will go towards the fee (to the miner). The raw transaction does not do any fee calculation. Example ...
user avatar
  • 7,060
5 votes

How do I sign and send a raw transaction using BitcoinJ?

I'm not an expert in this field by any means (and my error message was different), but I spent last week trying to make Bitcoinj sign a transaction and send in raw form (i.e. without using transport ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible