Bitcoin
¿Listo para usar esto en producción?
El plan gratuito cubre proyectos personales. El pago por uso escala sin necesidad de tarjeta.
Bitcoin
El plan gratuito cubre proyectos personales. El pago por uso escala sin necesidad de tarjeta.
Reading transaction data is one of the most common jobs in any Bitcoin application. A block explorer renders the inputs and outputs of every spend, a wallet checks whether an expected payment arrived and for how much, and a payment processor matches an incoming txid to an invoice and reads the exact BTC value. Because Bitcoin has no account ledger to query, all of this comes from decoding the transactions themselves. This guide shows how to fetch a transaction by txid with getrawtransaction, decode raw hex you already hold with decoderawtransaction, and interpret the resulting structure — the inputs being spent, the outputs being created, and the segwit and verbosity details that change what fields you get back from https://bitcoin.therpc.io/YOUR_API_KEY.
txid is the canonical identifier, hash is the witness-inclusive identifier, version flags consensus rules, size is the raw byte length, vsize is the weight-adjusted virtual size used for fees, weight is the BIP-141 weight units, and locktime is the earliest height or timestamp at which the transaction may confirm (0 means no lock).vin entry describes one input being spent: the previous txid and vout index it consumes, a scriptSig for legacy spends, a txinwitness array for segwit spends, and a sequence value that also signals opt-in RBF.vout entry describes one new output: value in BTC, the output index n, and a scriptPubKey object carrying the locking script, its type (for example witness_v0_keyhash or witness_v1_taproot), and the derived address when one exists.hash differs from txid and vsize differs from size, because witness data is committed in the hash and weighted at one quarter the cost. Always key your records on txid, never on hash, since the witness can be stripped without changing the txid.0/false returns plain hex, 1/true returns decoded JSON, and 2 returns the decoded JSON plus a computed fee and the spent prevout for each input (Bitcoin Core 24.0 and later). Request only the level you need.getrawtransaction needs an index to look up arbitrary txids. Without -txindex the node can only resolve transactions still in the mempool or in a block you name, so for a confirmed txid pass the containing blockhash as the third positional argument, or confirm the node runs txindex with getindexinfo before relying on bare-txid lookups.decoderawtransaction when you already hold the raw hex (for example freshly built or received out-of-band) and want to parse it with no chain lookup; use getrawtransaction when you only have a txid and need the node to find the bytes on chain.txid and vout, fetching that previous transaction, and reading its vout[n]. At verbosity 2 the node does this for you and embeds the prevout directly on each input, saving a round trip per input.fee or prevout are present below verbosity 2. Those fields only appear at verbosity 2 on Core 24.0+; at verbosity 1 you must compute the fee yourself as inputs minus outputs after resolving every prevout.blockhash, confirmations, and time; a mempool transaction has none of these. Branch on the presence of blockhash rather than reading confirmations, which is simply absent for unconfirmed transactions.