Jump to content
Sign in to follow this  
imgrooot

How do I a retrieve value from this output?

Recommended Posts

I am trying to using this API.   https://www.blocktrail.com/api/docs

 

 

I can retrieve the first layer value using this.

$global_trans_id        = $client->transaction($post_transid);
$api_transaction_id	= $global_trans_id['hash'];
echo $api_transaction_id;

As you see "hash" is the first layer below. But what if I want to retrieve the second layer such as a value from "Inputs" or "Outputs" like "$global_trans_id['address'];". How would that look?

{
    "hash": "c326105f7fbfa4e8fe971569ef8858f47ee7e4aa5e8e7c458be8002be3d86aad",
    "first_seen_at": "2014-03-11T08:27:57+0000",
    "last_seen_at": "2014-03-11T08:27:57+0000",
    "block_height": 290000,
    "block_time": "2014-03-11T08:27:57+0000",
    "block_hash": "0000000000000000fa0b2badd05db0178623ebf8dd081fe7eb874c26e27d0b3b",
    "confirmations": 31130,
    "is_coinbase": false,
    "estimated_value": 70000000,
    "total_input_value": 70070000,
    "total_output_value": 70030000,
    "total_fee": 40000,
    "estimated_change": 30000,
    "estimated_change_address": "19M1EraiuAvZp8ZV7QJHH2LVkYm8ECufCJ",
    "high_priority": false,
    "enough_fee": true,
    "contains_dust": false,
    "inputs": [
        {
            "index": 0,
            "output_hash": "d283ab6edd394b8a69d6943ea3a29a679d92176b112b1f69ffb9b70cf27dec5a",
            "output_index": 2769,
            "value": 2730000,
            "address": "19M1EraiuAvZp8ZV7QJHH2LVkYm8ECufCJ",
            "type": "pubkeyhash",
            "multisig": null,
            "script_signature": "0x49 0x3046022100bb3d102afd0d57be618aeaa7432bc038dea928bec0af6b8cba37c7ec85701e3d022100c467073956b385f08fbfbc2e130d8f76deb7c5436ba245afca4678200b127c2001 0x21 0x02aa6584518e528be497be65fba84913b7d0cb55158f4e7922298923286a7f6156"
        },
        {
            "index": 1,
            "output_hash": "b350de75f9c27b457fa6cefb7072af8aa94de53ccedff4ec06ce885d63645e1d",
            "output_index": 2764,
            "value": 2740000,
            "address": "19M1EraiuAvZp8ZV7QJHH2LVkYm8ECufCJ",
            "type": "pubkeyhash",
            "multisig": null,
            "script_signature": "0x48 0x3045022059c6cc77c0a7c3a3a1ab0678690178750f2b5e442dc6f9331835be4cdb087cc00221008fca79860ab8f15acba61522b4f8482909cadfdf79dca7790efabf71c7c12d3701 0x21 0x02aa6584518e528be497be65fba84913b7d0cb55158f4e7922298923286a7f6156"
        },
        {
            "index": 2,
            "output_hash": "fa3f040de013ddbe4a5746c89d32de2cac147845682e7d26119fd686a57e0b65",
            "output_index": 2549,
            "value": 2930000,
            "address": "19M1EraiuAvZp8ZV7QJHH2LVkYm8ECufCJ",
            "type": "pubkeyhash",
            "multisig": null,
            "script_signature": "0x47 0x304402207266d8c69d2c28e4050a90f48209768554e1470999a2259b000fd3c096edc39f02207b7f6a6b7ca7952249a1a1f3064e6a3f573fcd6700084e2fe71ce8f3d3f2be8301 0x21 0x02aa6584518e528be497be65fba84913b7d0cb55158f4e7922298923286a7f6156"
        },
        { /* ... */ }
    ],
    "outputs": [
        {
            "index": 0,
            "value": 70000000,
            "address": "1JSywyhFSvCC4NGALvKoyX5xng86QaigAN",
            "type": "pubkeyhash",
            "multisig": null,
            "script": "DUP HASH160 0x14 0xbf641337e3ab4eaae788a72bafedb965749882b2 EQUALVERIFY CHECKSIG",
            "script_hex": "76a914bf641337e3ab4eaae788a72bafedb965749882b288ac",
            "spent_hash": "71acf863d37d9d18524607e3dd68128b91ddc43dfe32f620ec124ceff3bb3295",
            "spent_index": 34
        },
        {
            "index": 1,
            "value": 30000,
            "address": "19M1EraiuAvZp8ZV7QJHH2LVkYm8ECufCJ",
            "type": "pubkeyhash",
            "multisig": null,
            "script": "DUP HASH160 0x14 0x5b8986608535c96923769138ad5be236a091b791 EQUALVERIFY CHECKSIG",
            "script_hex": "76a9145b8986608535c96923769138ad5be236a091b79188ac",
            "spent_hash": "400f77fff18e24d1a770c0e1ca85434ca5e4cd0f6e1489e5849256cc71f9ec0a",
            "spent_index": 2
        },
        { /* ... */ }
    ]
}
Edited by imgrooot

Share this post


Link to post
Share on other sites

$global_trans_id['inputs'][0]['index'] would be the index of the first set of input values (index 0). You can do a foreach on $global_trans_id['inputs'] to loop through them all.

  • Like 1

Share this post


Link to post
Share on other sites

Sepodati is correct. But to your specific question:

 

 

echo $global_trans_id['inputs'][0]['address'];
As already pointed out, the sample data you provided shows that both the 'inputs' and 'outputs' keys are array (note: [ ] ).

 

Each array has apparently a variable number of elements in the array. So if you wanted to see all the addresses:

 

foreach ($global_trans_id['inputs'] as $value) {
    
    echo "Address:  {$value['address']} <br>";
} 

Share this post


Link to post
Share on other sites

Sepodati is correct. But to your specific question:

 

 

echo $global_trans_id['inputs'][0]['address'];
As already pointed out, the sample data you provided shows that both the 'inputs' and 'outputs' keys are array (note: [ ] ).

 

Each array has apparently a variable number of elements in the array. So if you wanted to see all the addresses:

 

foreach ($global_trans_id['inputs'] as $value) {
    
    echo "Address:  {$value['address']} <br>";
} 

Awesome. That's that i needed. Thanks.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.