1

I am developing a web application in PHP. I wish to be able to detect incoming transactions whenever they come, by using the 'listunspent' Bitcoin JSON RPC call. As expected, a long list of transactions are spewed out. My problem is that I don't see how I would be able to deal with each of the transactions in the array. I tried using this code to test with at first:

function processTransaction() {
    global $bitcoin;
    $unspent = $bitcoin->listunspent();
    $address = $unspent['address'];
    echo $address;
} 

However, as expected, the function does not work. I am guessing that I would have to loop through the entire 'unspent' array and deal with each transaction individually. This is where I get stuck. How do I select or loop through this entire array?

Also, once I have dealt with a transaction, is there a way to mark the transaction as 'spent'? Is there a way to do this without having to send the coins to another wallet?

The kind of code I think I would have to use is something similar to this:

function processTransaction() {
    global $bitcoin;
    $unspent = $bitcoin->listunspent();

        foreach ($unspent as $address) {
            //...do something with the address
            //...mark transaction as 'spent'
        }
}

(Just so that you are in context with the question, here is a brief overview of the site I am developing. The site is called 'Vertodds' and what it is, is a gambling site. You enter in your Vertcoin address and a new unique deposit address is created for you. You can then deposit VTC into your unique deposit address, and there is a 49% chance of doubling your coin.)

Thank you very much for your time and knowledge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.