I'm looking for a way to get address from scriptSig. I want to know input address. Can you share how to do it? I prefer PHP library but any ways would be appreciated.
e.g.
I use bitwasp, a PHP library. I can see a scriptSig ("483...767") in vin. I want to decode it so that I can get the source addresses.
PHP sample
<?php
require_once 'vendor/autoload.php';
use BitWasp\BitcoinLib\RawTransaction;
$hex = '0100000001e7bb795fa90136f4052a99a433a16d71406261dec7eaff2a2a03ce7254bb4159010000006b483045022100f5b10c765ae5116917ddf9b8c4e8d07996b37ad934c005396e7dcda70e7621ee022014cf65f5cc46e229fbcfe7259b3f8c9d0b0c3cd446c4307a8872ad6cc0d538b401210396f8781a4900372a5d72d84718d146170d5983e67dff8b4a28fef80690c09767ffffffff035f150000000000001976a9143e37de641b25616304415a72bc556824f442004588ac00000000000000001e6a1c54f55fe6f2a0f349e2921d06e63d58712a906fbb4231f1e943da82d6313d1300000000001976a9142f7dcdf7cda481fe0f123d4c62bf830605e9f54d88ac00000000';
$tx_data = RawTransaction::decode($hex);
print(json_encode($tx_data));
Output
{
"txid":"55a8f0d5852745ab2d80358ff4ae6fdbfeab0e4dc94b3474d1c5538e0579bb95",
"version":"1",
"vin":[
{
"txid":"5941bb5472ce032a2affeac7de616240716da133a4992a05f43601a95f79bbe7",
"vout":1,
"scriptSig":{
"asm":"3045022100f5b10c765ae5116917ddf9b8c4e8d07996b37ad934c005396e7dcda70e7621ee022014cf65f5cc46e229fbcfe7259b3f8c9d0b0c3cd446c4307a8872ad6cc0d538b401 0396f8781a4900372a5d72d84718d146170d5983e67dff8b4a28fef80690c09767",
"hex":"483045022100f5b10c765ae5116917ddf9b8c4e8d07996b37ad934c005396e7dcda70e7621ee022014cf65f5cc46e229fbcfe7259b3f8c9d0b0c3cd446c4307a8872ad6cc0d538b401210396f8781a4900372a5d72d84718d146170d5983e67dff8b4a28fef80690c09767"
},
"sequence":4294967295
}
],
"vout":[
{
"value":"0.00005471",
"vout":0,
"scriptPubKey":{
"asm":"OP_DUP OP_HASH160 3e37de641b25616304415a72bc556824f4420045 OP_EQUALVERIFY OP_CHECKSIG",
"hex":"76a9143e37de641b25616304415a72bc556824f442004588ac",
"type":"pubkeyhash",
"reqSigs":1,
"hash160":"3e37de641b25616304415a72bc556824f4420045",
"addresses":[
"16fypikbjmmfroCHUhDLhczngCfL6BgccH"
]
}
},
{
"value":"0.00000000",
"vout":1,
"scriptPubKey":{
"asm":"OP_RETURN 54f55fe6f2a0f349e2921d06e63d58712a906fbb4231f1e943da82d6",
"hex":"6a1c54f55fe6f2a0f349e2921d06e63d58712a906fbb4231f1e943da82d6",
"message":"unable to decode tx type!"
}
},
{
"value":"0.01260849",
"vout":2,
"scriptPubKey":{
"asm":"OP_DUP OP_HASH160 2f7dcdf7cda481fe0f123d4c62bf830605e9f54d OP_EQUALVERIFY OP_CHECKSIG",
"hex":"76a9142f7dcdf7cda481fe0f123d4c62bf830605e9f54d88ac",
"type":"pubkeyhash",
"reqSigs":1,
"hash160":"2f7dcdf7cda481fe0f123d4c62bf830605e9f54d",
"addresses":[
"15L7U55PAsHLEpQkZqz62e3eqWd9AHb2DH"
]
}
}
],
"locktime":"0"
}
Update 1
The following is a screenshot of blockchain.info
https://blockchain.info/ja/tx/10857ad56f1695559562af8076aea4ccba625ba79a82f75e5658c0c2fa4336c0
I'm wondering how I can get the source address "1J16FUpZsS6My1FqHXpka5fztAnyFsBPf1".
Update 2
I found a similar question and retrieving previous transaction was proposed. It may work but I want to decode hex so that it can reduce cost to access bitcoind.
How to get the Input Address from vin where only a txid is given (Insight-Api)
Update 3
This is also taking same approach. It may impossible to decode the scriptsig...
How to findout the sender of a transaction
Update 4
This explains why it is impossible. Okay I give up decoding scriptsig. I'll retrieve it by txid.
Due to the nature of the pay-to-pubkey script, the script sig does not contain the pubkey anymore (just the signature).
Update 5 (Solved)
theStack gave me the best answer. Following the answer, I tried it in PHP with Bitwasp.
<?php
require_once 'vendor/autoload.php';
use BitWasp\BitcoinLib\BitcoinLib;
use BitWasp\BitcoinLib\RawTransaction;
$hex = '0100000001e7bb795fa90136f4052a99a433a16d71406261dec7eaff2a2a03ce7254bb4159010000006b483045022100f5b10c765ae5116917ddf9b8c4e8d07996b37ad934c005396e7dcda70e7621ee022014cf65f5cc46e229fbcfe7259b3f8c9d0b0c3cd446c4307a8872ad6cc0d538b401210396f8781a4900372a5d72d84718d146170d5983e67dff8b4a28fef80690c09767ffffffff035f150000000000001976a9143e37de641b25616304415a72bc556824f442004588ac00000000000000001e6a1c54f55fe6f2a0f349e2921d06e63d58712a906fbb4231f1e943da82d6313d1300000000001976a9142f7dcdf7cda481fe0f123d4c62bf830605e9f54d88ac00000000';
$tx = RawTransaction::decode($hex);
$asm = explode(' ', $tx['vin'][0]['scriptSig']['asm']);
$address = BitcoinLib::public_key_to_address($asm[1], '00');
print($address); // 15L7U55PAsHLEpQkZqz62e3eqWd9AHb2DHyusaku