Join 60,569 users and earn money for participation
read.cash is a platform where you could earn money (total earned by users so far: $ 292,255.44).
You could get tips for writing articles and comments, which are paid in Bitcoin Cash (BCH) cryptocurrency,
which can be spent on the Internet or converted to your local money.
Takes one minute, no documents required
«What are the addresses involved in this transaction?» using Python
A Bitcoin Cash transaction contains no addresses, yet whenever we're presented with a transaction in a graphical interface, we always get to see the addresses involved. Let's find a recent transaction in a block explorer:
I use the python bitcoincash library, in addition I have a full node running that supports the satoshi client RPC interface. In this case Bitcoin Unlimited.
The CScript here is the ScriptPubKey of the transaction output. It looks like the most common used script in Bitcoin Cash, the Pay-to-PubKey Hash (P2PKH).
Pay-to-PubKey Hash has the standard template OPDUP OPHASH160 <pubKeyHash> OPEQUALVERIFY OPCHECKSIG. And this can be represented as a Bitcoin Cash address.
The python library has a built in function to derive this, continuing the script above:
from bitcoincash.wallet import CBitcoinAddress
print("Outputs:")
for o in tx.vout:
print(str(CBitcoinAddress.from_scriptPubKey(o.scriptPubKey)))
The transaction pretty much only contains pointers to previous transaction and no other info. So to find the input addresses, we need to fetch the parent transactions to get their scriptPubKey.
print("Inputs:")
for i in tx.vin:
prevout = i.prevout
prevtx = rpc.getrawtransaction(prevout.hash)
script_from_input = prevtx.vout[prevout.n].scriptPubKey
print(str(CBitcoinAddress.from_scriptPubKey(script_from_input)))