<p>The <code>transfer amount (BTC)</code> is, (somewhat dependant on the library used),  most commonly denominated as "value:"
Read: the outs => value: *</p>

<pre><code> {
      value: 1000000,
      script: &lt;Buffer a9 14 14 ea 69 2e 87 76 ec c6 2e 6a aa a1 7d cc d2 8f f3 30 b7 46 87&gt;
    },
    {
      value: 3299775,
      script: &lt;Buffer a9 14 73 e2 99 78 43 31 1e cc 32 b5 ac 38 ef c9 9b b3 ae 54 bc 7c 87&gt;
    }
</code></pre>

<p>Where the value is most often denominated in satoshis (a single unit.). But, some block explorers (blockchair) or other libraries will denominate in single units of Bitcoin, as is done below. (10^8 satoshis - 1 BTC ( 100 mil))</p>

<p>1000000 = 0.01BTC
3299775 = 0.03299775 BTC</p>

CC BY-SA 4.0
2020-01-09T20:51:31.180Z
2020-01-09T20:51:31.180Z
Jan Janssen
<p>I'm assuming you mean you want to know how many sats were sent from previous outputs (and how much was paid in fees).</p>
<p>This is not encoded in the tx itself. You need to get that information from your Bitcoin node (or from an explorer API like Blockstream's). You need to retrieve all previous input transactions and then look at the values in the outputs that your tx consumed. The tx contains the ids of the previous tx. You just have to go get that information.</p>
<p>This will do the trick:</p>
<pre><code>import { Transaction } from 'bitcoinjs-lib';
import fetch from 'cross-fetch';

//I took a random recent tx from the blockchain:
const rawTx =
  '01000000000102f1950b9b14422ccb4214c0411a722d436f6b78aa35135ab87da42ec20a9ebf2900000000171600148e2d687d3dc2d5f2505809f212d90b3725bb78c0fdffffffc5e2cf7beaf2a14e57d530a88224e48673e6b8aa9f70d1c785ffc4618a0f89f001000000171600147606ee140cae2a5a47ad580e37a8e2557c05d12efdffffff02844402000000000017a914ec4c86acc0023962981f9d9585cab245e12b0859872eca0f0000000000160014330692d03439fe8ddb88df7b97fa834b975ea41002483045022100b6eced5373a7c37e9be7e4cbe070b880406fae7eba94519e8ddb35510889df4d02205cb95d1b9333f8713ea416f1a2f5d7d685418cad66d4b5c6a5f6b28ddecc955b012102d105008f859c9e9388c56fbe3432c077c731549c6f2807e44136b7de44abffe30248304502210085726ec64c7a614de6997705e86efdb78463d99a6be81128db2151e1869c6bbf022067e42c75755ea5ea922e29fae4a5a0b963de1f17faf8e5b9e4f767115a62e726012102555dabf7c0ecf054f1a0ae1a80980851d9b3b57060c59048c887709c62c7542900000000';

const outputValue = Transaction.fromHex(rawTx)
  .outs.map(out =&gt; out.value)
  .reduce((sum, value) =&gt; sum + value, 0);

let inputValue = 0;
for (const input of Transaction.fromHex(rawTx).ins) {
  const txid = Buffer.from(input.hash).reverse().toString('hex');
  const response = await fetch(`https://blockstream.info/api/tx/${txid}/hex`);
  const rawTx = await response.text();
  inputValue += Transaction.fromHex(rawTx).outs[input.index].value;
}

console.log({ inputValue, outputValue, fees: inputValue - outputValue });
</code></pre>

CC BY-SA 4.0
2022-05-29T06:57:12.857Z
2022-05-29T06:57:12.857Z
landabaso
<p>Suppose I have following object</p>

<pre><code>console.log(bitcoinjs.Transaction.fromHex(rawTx));

</code></pre>

<p>The output</p>

<pre><code>Transaction {
  version: 2,
  locktime: 1655960,
  ins: [
    {
      hash: &lt;Buffer dc 4d aa 10 db 80 36 52 24 49 7c c5 7c bc c5 bc df be e1 2d 58 61 70 e1 0c 7b 76 a7 35 cc 7c 3a&gt;,
      index: 21,
      script: &lt;Buffer 16 00 14 5f f3 9b e6 42 af a9 f3 59 25 34 e7 6a dd b2 ee e3 41 82 15&gt;,
      sequence: 4294967294,
      witness: [Array]
    }
  ],
  outs: [
    {
      value: 1000000,
      script: &lt;Buffer a9 14 14 ea 69 2e 87 76 ec c6 2e 6a aa a1 7d cc d2 8f f3 30 b7 46 87&gt;
    },
    {
      value: 3299775,
      script: &lt;Buffer a9 14 73 e2 99 78 43 31 1e cc 32 b5 ac 38 ef c9 9b b3 ae 54 bc 7c 87&gt;
    }
  ]
}
</code></pre>

<p>How can I decode transfer amount (in BTC) from this object?</p>

CC BY-SA 4.0
2020-01-09T15:07:19.603Z
What do you mean by "transfer amount"? You have the output values there...
pinhead
CC BY-SA 4.0
2021-02-03T18:42:57.480Z
You have the output value, which is the funds that get sent somewhere. That's probably enough for most applications. But you don't know how the value of any of the inputs, and therefore you also can't tell how much was paid in fees. If you can look up the inputs of this transaction, you'll have all the information you want!
karimkorun
<transactions><raw-transaction><javascript><bitcoinjs>
How to get BTC transfer amount from raw tx using bitcoinjs
Michael Khoroshun
# How to get BTC transfer amount from raw tx using bitcoinjs

(Asked by: username_0 on 2020-01-09)

Suppose I have following object
console.log(bitcoinjs.Transaction.fromHex(rawTx));


The output
Transaction {
  version: 2,
  locktime: 1655960,
  ins: [
    {
      hash: ,
      index: 21,
      script: ,
      sequence: 4294967294,
      witness: [Array]
    }
  ],
  outs: [
    {
      value: 1000000,
      script: 
    },
    {
      value: 3299775,
      script: 
    }
  ]
}

How can I decode transfer amount (in BTC) from this object?

**Tags:** transactions, raw-transaction, javascript, bitcoinjs

> **Comments:**
> **username_1**: What do you mean by "transfer amount"? You have the output values there...  
> **username_2**: You have the output value, which is the funds that get sent somewhere. That's probably enough for most applications. But you don't know how the value of any of the inputs, and therefore you also can't tell how much was paid in fees. If you can look up the inputs of this transaction, you'll have all the information you want!  

---

## 2 answers

### Answer by username_3 on 2020-01-09. Score: 1

The transfer amount (BTC) is, (somewhat dependant on the library used),  most commonly denominated as "value:"
Read: the outs => value: *
 {
      value: 1000000,
      script: 
    },
    {
      value: 3299775,
      script: 
    }

Where the value is most often denominated in satoshis (a single unit.). But, some block explorers (blockchair) or other libraries will denominate in single units of Bitcoin, as is done below. (10^8 satoshis - 1 BTC ( 100 mil))
1000000 = 0.01BTC
3299775 = 0.03299775 BTC


---

### Answer by username_4 on 2022-05-29. Score: 0

I'm assuming you mean you want to know how many sats were sent from previous outputs (and how much was paid in fees).
This is not encoded in the tx itself. You need to get that information from your Bitcoin node (or from an explorer API like Blockstream's). You need to retrieve all previous input transactions and then look at the values in the outputs that your tx consumed. The tx contains the ids of the previous tx. You just have to go get that information.
This will do the trick:
import { Transaction } from 'bitcoinjs-lib';
import fetch from 'cross-fetch';

//I took a random recent tx from the blockchain:
const rawTx =
  '01000000000102f1950b9b14422ccb4214c0411a722d436f6b78aa35135ab87da42ec20a9ebf2900000000171600148e2d687d3dc2d5f2505809f212d90b3725bb78c0fdffffffc5e2cf7beaf2a14e57d530a88224e48673e6b8aa9f70d1c785ffc4618a0f89f001000000171600147606ee140cae2a5a47ad580e37a8e2557c05d12efdffffff02844402000000000017a914ec4c86acc0023962981f9d9585cab245e12b0859872eca0f0000000000160014330692d03439fe8ddb88df7b97fa834b975ea41002483045022100b6eced5373a7c37e9be7e4cbe070b880406fae7eba94519e8ddb35510889df4d02205cb95d1b9333f8713ea416f1a2f5d7d685418cad66d4b5c6a5f6b28ddecc955b012102d105008f859c9e9388c56fbe3432c077c731549c6f2807e44136b7de44abffe30248304502210085726ec64c7a614de6997705e86efdb78463d99a6be81128db2151e1869c6bbf022067e42c75755ea5ea922e29fae4a5a0b963de1f17faf8e5b9e4f767115a62e726012102555dabf7c0ecf054f1a0ae1a80980851d9b3b57060c59048c887709c62c7542900000000';

const outputValue = Transaction.fromHex(rawTx)
  .outs.map(out => out.value)
  .reduce((sum, value) => sum + value, 0);

let inputValue = 0;
for (const input of Transaction.fromHex(rawTx).ins) {
  const txid = Buffer.from(input.hash).reverse().toString('hex');
  const response = await fetch(`https://blockstream.info/api/tx/${txid}/hex`);
  const rawTx = await response.text();
  inputValue += Transaction.fromHex(rawTx).outs[input.index].value;
}

console.log({ inputValue, outputValue, fees: inputValue - outputValue });


---

