1

I am trying to find details of every transaction using bitcoin core rpc. First, I using bitcoin-cli getblock to get the block data, then use bitcoin-cli getrawtransaction to get the transaction details.

For instance:

 bitcoin-cli getrawtransaction "1024cb12a576b69defa67dbc2f1899700ab58e5ad3d5e058edefb907f59865bc" true "00000000000000000024fb37364cbf81fd49cc2d51c09c75c35433c3a1945d04" 

get:

{
  "in_active_chain": true,
  "txid": "1024cb12a576b69defa67dbc2f1899700ab58e5ad3d5e058edefb907f59865bc",
  "hash": "1024cb12a576b69defa67dbc2f1899700ab58e5ad3d5e058edefb907f59865bc",
  "version": 2,
  "size": 339,
  "vsize": 339,
  "weight": 1356,
  "locktime": 499989,
  "vin": [
    {
      "txid": "0d6cbc21a1b1a3e5df1eae4fc37aa849174b6b727e53f9f505a605f066b7f000",
      "vout": 0,
      "scriptSig": {
        "asm": "304402203f198d9695a293c41d2124e790d473e68f4b35a09ece5517c7adfffc797f91760220304feb1cc2829d3c937665bcb4b7f9735acbcac50e9169bc53c9e689ce20b3bc[ALL] 025743bce4e775bb754e784dd2cfdc8dabc2023154eee539bb155612101a583e7e",
        "hex": "47304402203f198d9695a293c41d2124e790d473e68f4b35a09ece5517c7adfffc797f91760220304feb1cc2829d3c937665bcb4b7f9735acbcac50e9169bc53c9e689ce20b3bc0121025743bce4e775bb754e784dd2cfdc8dabc2023154eee539bb155612101a583e7e"
      },
      "sequence": 4294967294
    },
    {
      "txid": "aac498279d50ee81237d704cb495b243b50def5ecdcb36d9d78f596f73b1d3e9",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100b763b986b17beddac1ac96c3656fa7af188a28cfacfc87390e1e796b7fdbc0d102201e76f77db6093306028e681e2fe6354ae12649afb5c27c549243b67d505a1bb6[ALL] 0349ebb9d180938ab3a571d8c2e9771fb4fecb9f4484c337bb35d8fd8b48283ca9",
        "hex": "483045022100b763b986b17beddac1ac96c3656fa7af188a28cfacfc87390e1e796b7fdbc0d102201e76f77db6093306028e681e2fe6354ae12649afb5c27c549243b67d505a1bb601210349ebb9d180938ab3a571d8c2e9771fb4fecb9f4484c337bb35d8fd8b48283ca9"
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 0.17450000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c0 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c088ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1LXnPYpHTwQeWfBVnQZ4yDP23b57NwoyrP"
        ]
      }
    }
  ],
  "hex": "020000000200f0b766f005a605f5f9537e726b4b1749a87ac34fae1edfe5a3b1a121bc6c0d000000006a47304402203f198d9695a293c41d2124e790d473e68f4b35a09ece5517c7adfffc797f91760220304feb1cc2829d3c937665bcb4b7f9735acbcac50e9169bc53c9e689ce20b3bc0121025743bce4e775bb754e784dd2cfdc8dabc2023154eee539bb155612101a583e7efeffffffe9d3b1736f598fd7d936cbcd5eef0db543b295b44c707d2381ee509d2798c4aa010000006b483045022100b763b986b17beddac1ac96c3656fa7af188a28cfacfc87390e1e796b7fdbc0d102201e76f77db6093306028e681e2fe6354ae12649afb5c27c549243b67d505a1bb601210349ebb9d180938ab3a571d8c2e9771fb4fecb9f4484c337bb35d8fd8b48283ca9feffffff0110440a01000000001976a914d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c088ac15a10700",
  "blockhash": "00000000000000000024fb37364cbf81fd49cc2d51c09c75c35433c3a1945d04",
  "confirmations": 85927,
  "time": 1513622125,
  "blocktime": 1513622125
}

I know some web api such as blockchain.info provide these information for every transaction. How can I get the address and corresponding amount of vin using other bitcoin core rpc?

Thanks.

There some related links: How to get address from scriptSig?

How to get the Input Address from vin where only a txid is given (Insight-Api)

0

2 Answers 2

4

The address and amount of the sender can be gotten from the 'txid' and 'vout' by using getrawtransaction command. Let's see the example, the vin part of the block is as follows:

"vin": [
    {
      "txid": "0d6cbc21a1b1a3e5df1eae4fc37aa849174b6b727e53f9f505a605f066b7f000",
      "vout": 0,
      "scriptSig": {
        "asm": "304402203f198d9695a293c41d2124e790d473e68f4b35a09ece5517c7adfffc797f91760220304feb1cc2829d3c937665bcb4b7f9735acbcac50e9169bc53c9e689ce20b3bc[ALL] 025743bce4e775bb754e784dd2cfdc8dabc2023154eee539bb155612101a583e7e",
        "hex": "47304402203f198d9695a293c41d2124e790d473e68f4b35a09ece5517c7adfffc797f91760220304feb1cc2829d3c937665bcb4b7f9735acbcac50e9169bc53c9e689ce20b3bc0121025743bce4e775bb754e784dd2cfdc8dabc2023154eee539bb155612101a583e7e"
      },
      "sequence": 4294967294
    },
    {
      "txid": "aac498279d50ee81237d704cb495b243b50def5ecdcb36d9d78f596f73b1d3e9",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100b763b986b17beddac1ac96c3656fa7af188a28cfacfc87390e1e796b7fdbc0d102201e76f77db6093306028e681e2fe6354ae12649afb5c27c549243b67d505a1bb6[ALL] 0349ebb9d180938ab3a571d8c2e9771fb4fecb9f4484c337bb35d8fd8b48283ca9",
        "hex": "483045022100b763b986b17beddac1ac96c3656fa7af188a28cfacfc87390e1e796b7fdbc0d102201e76f77db6093306028e681e2fe6354ae12649afb5c27c549243b67d505a1bb601210349ebb9d180938ab3a571d8c2e9771fb4fecb9f4484c337bb35d8fd8b48283ca9"
      },
      "sequence": 4294967294
    }
  ]

It means that there are two inputs, the first input is from the "vout" 0 of the transaction "txid" "0d6cbc21a1b1a3e5df1eae4fc37aa849174b6b727e53f9f505a605f066b7f000", the second input is from the "vout" 1 fo the transaction "txid": "aac498279d50ee81237d704cb495b243b50def5ecdcb36d9d78f596f73b1d3e9". Since the vout part of one transaction has address and amount, we can get the input address and corresponding amount.

For instance, let's look the first input:

      "txid": "0d6cbc21a1b1a3e5df1eae4fc37aa849174b6b727e53f9f505a605f066b7f000",
      "vout": 0,

run following core rpc command (note that we need let the server index each transaction to support getrawtransaction, it can be done by add "txindex=1" in the bitcoin.conf)

bitcoin-cli -rpcuser=jun -rpcpassword=123 getrawtransaction "0d6cbc21a1b1a3e5df1eae4fc37aa849174b6b727e53f9f505a605f066b7f000" true

We get following vouts part as follows:

 "vout": [
    {
      "value": 0.01040000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 af9e84db382823b9c36c40d70090ff81890c5ef5 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914af9e84db382823b9c36c40d70090ff81890c5ef588ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1H1b9fN7wYYwTSweyPjE7wCGSHuduCcE2o"
        ]
      }
    },
    {
      "value": 147.75014395,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 35f72ce8b9123a055e27be9a0bb723b6cb502419 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a91435f72ce8b9123a055e27be9a0bb723b6cb50241988ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "15vLvDZyAjWCrfWyazMtvHRe8hDJBxXJEC"
        ]
      }
    }
  ],

Then we have the address and amount which are the first part of the vout. It is the first input of our transaction.

"addresses": ["1H1b9fN7wYYwTSweyPjE7wCGSHuduCcE2o"]
"value": 147.75014395

There is a very nice blog about the vin and vout explanation http://www.michaelnielsen.org/ddi/how-the-bitcoin-protocol-actually-works/

0

I had an problem equals and I used The client bitcoin for C++, but if you want to get the address of the transaction with the command decodescript and the hex script,

with your example with your I ran in the console bitcoin-qt this command

decodescript 76a914d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c088ac

an I got this information

{
  "asm": "OP_DUP OP_HASH160 d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c0 OP_EQUALVERIFY OP_CHECKSIG",
  "reqSigs": 1,
  "type": "pubkeyhash",
  "addresses": [
    "1LXnPYpHTwQeWfBVnQZ4yDP23b57NwoyrP"
  ],
  "p2sh": "3Mn9qFsLMF4AQK2MMadtUW9im7GF95piQo",
  "segwit": {
    "asm": "0 d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c0",
    "hex": "0014d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c0",
    "reqSigs": 1,
    "type": "witness_v0_keyhash",
    "addresses": [
      "bc1q6c7vrcakqz0rr5pm6huqgm97palr06xq5xedry"
    ],
    "p2sh-segwit": "3BmcGFkh7jJTsWGRSt4zBFJGyBuGWtFsUN"
  }
}

the value of bitcoin in the transaction is into json the blockchain.info with propriety value, but if you want to get transaction information to the client bitcoin you can use this command, with your case

decoderawtransaction 020000000200f0b766f005a605f5f9537e726b4b1749a87ac34fae1edfe5a3b1a121bc6c0d000000006a47304402203f198d9695a293c41d2124e790d473e68f4b35a09ece5517c7adfffc797f91760220304feb1cc2829d3c937665bcb4b7f9735acbcac50e9169bc53c9e689ce20b3bc0121025743bce4e775bb754e784dd2cfdc8dabc2023154eee539bb155612101a583e7efeffffffe9d3b1736f598fd7d936cbcd5eef0db543b295b44c707d2381ee509d2798c4aa010000006b483045022100b763b986b17beddac1ac96c3656fa7af188a28cfacfc87390e1e796b7fdbc0d102201e76f77db6093306028e681e2fe6354ae12649afb5c27c549243b67d505a1bb601210349ebb9d180938ab3a571d8c2e9771fb4fecb9f4484c337bb35d8fd8b48283ca9feffffff0110440a01000000001976a914d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c088ac15a10700

and I got this result

{
  "txid": "1024cb12a576b69defa67dbc2f1899700ab58e5ad3d5e058edefb907f59865bc",
  "hash": "1024cb12a576b69defa67dbc2f1899700ab58e5ad3d5e058edefb907f59865bc",
  "version": 2,
  "size": 339,
  "vsize": 339,
  "weight": 1356,
  "locktime": 499989,
  "vin": [
    {
      "txid": "0d6cbc21a1b1a3e5df1eae4fc37aa849174b6b727e53f9f505a605f066b7f000",
      "vout": 0,
      "scriptSig": {
        "asm": "304402203f198d9695a293c41d2124e790d473e68f4b35a09ece5517c7adfffc797f91760220304feb1cc2829d3c937665bcb4b7f9735acbcac50e9169bc53c9e689ce20b3bc[ALL] 025743bce4e775bb754e784dd2cfdc8dabc2023154eee539bb155612101a583e7e",
        "hex": "47304402203f198d9695a293c41d2124e790d473e68f4b35a09ece5517c7adfffc797f91760220304feb1cc2829d3c937665bcb4b7f9735acbcac50e9169bc53c9e689ce20b3bc0121025743bce4e775bb754e784dd2cfdc8dabc2023154eee539bb155612101a583e7e"
      },
      "sequence": 4294967294
    },
    {
      "txid": "aac498279d50ee81237d704cb495b243b50def5ecdcb36d9d78f596f73b1d3e9",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100b763b986b17beddac1ac96c3656fa7af188a28cfacfc87390e1e796b7fdbc0d102201e76f77db6093306028e681e2fe6354ae12649afb5c27c549243b67d505a1bb6[ALL] 0349ebb9d180938ab3a571d8c2e9771fb4fecb9f4484c337bb35d8fd8b48283ca9",
        "hex": "483045022100b763b986b17beddac1ac96c3656fa7af188a28cfacfc87390e1e796b7fdbc0d102201e76f77db6093306028e681e2fe6354ae12649afb5c27c549243b67d505a1bb601210349ebb9d180938ab3a571d8c2e9771fb4fecb9f4484c337bb35d8fd8b48283ca9"
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 0.17450000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c0 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c088ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1LXnPYpHTwQeWfBVnQZ4yDP23b57NwoyrP"
        ]
      }
    }
  ]
}

For my opinion exist and alternative more simple and is use the client bitcoin, this is reference, I have used the C++ with this library bitcoin-api-cpp is very simple get all information to the node

The documentation of the command is there

I hope I understand your question and sorry my terrible English

3
  • Thanks. However, it cannot get the amount and address of the sender of the transaction yet.
    – Jun Fang
    Jul 19, 2019 at 2:51
  • The decodescript returned also the addresses, in the json and the amount is the json of the decoderawtransaction with propriety "value" Jul 19, 2019 at 8:19
  • Thanks for your replay. I have found the answer and will post it soon.
    – Jun Fang
    Jul 21, 2019 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.