Welcome to the Dash Forum!

Please sign up to discuss the most innovative cryptocurrency!

WalletNotify Script

Discussion in 'Development Tech Discussion' started by simplebtc, Oct 6, 2014.

  1. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Darkcoind provides a configuration parameter called walletnotify that accepts a script as its parameter. When the wallet receives a transaction for a local address it hits the script configured, passing the txid incoming.

    walletnotify.php is a self-contained PHP script for processing walletnotify calls. Use as is or customize for your own needs.

    Features
    • Processes darkcoind walletnotify calls and inserts the transaction into a database (MySQL or SQLite).
    • Sends email and SMS notifications on transactions affecting local DRK addresses.
    • Provides a simple interface for chaining other processes.
    Usage
    • Receive SMS or email update anytime funds are sent or received.
    • Process payments automatically whenever coins are received.
    • Automatically sweep coins to cold wallets.
    • Automatically pay affiliates / partners per transaction.

    [email protected]
     
    #1 simplebtc, Oct 6, 2014
    Last edited by a moderator: Oct 7, 2014
  2. Light

    Light Well-known Member
    Foundation Member

    Joined:
    Jun 4, 2014
    Messages:
    346
    Likes Received:
    256
    Trophy Points:
    233
    Can these sms and email updates about sent/received funds create a pattern overtime that can compromise the user?
     
  3. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Good question. The primary work of the script is to shove transactions affecting the local wallet into a database. For example, to process the transactions in queue by other scripts.

    WalletNotify is a stripped down version of a similar script that processes orders. Check out this one for reference: walletnotify.php.

    I wouldn't advise running it on a large storage wallet, no. You shouldn't need this type of processing on that kind of wallet.

    You can turn off all notifications by commenting out line #158.

    What was your planned use case?
     
    #3 simplebtc, Oct 7, 2014
    Last edited by a moderator: Oct 7, 2014
  4. fernando

    fernando Powered by Dash
    Dash Core Team Foundation Member Moderator

    Joined:
    May 9, 2014
    Messages:
    1,528
    Likes Received:
    2,061
    Trophy Points:
    283
    I understand that you need to have the wallet running for this to work, don't you?
     
  5. flare

    flare Administrator
    Dash Core Team Moderator

    Joined:
    May 18, 2014
    Messages:
    2,287
    Likes Received:
    2,406
    Trophy Points:
    1,183
    Correct, the script is executed each time the event occurs - running wallet mandatory.
     
  6. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Yes, the wallet itself calls whatever script is configured in the walletnotify parameter whenever it receives an update from the blockchain that affects one of its addresses.
     
  7. Rux

    Rux Member

    Joined:
    Mar 9, 2014
    Messages:
    68
    Likes Received:
    32
    Trophy Points:
    58
    Hi guys im very interested in this script but im having problems setting it up on wamp to test it

    when i open cmd and go to php, type
    php -f walletnotify.php <txid>

    after 30-60sec it returns
    [​IMG]

    when i go to phpmyadmin ... my database walletnotify and table walletnotify is empty :)

    any clues? ;) im noob so dont mind me please :D
     
  8. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Have you checked your PHP error log? There are multiple error_log() statements during execution that should be outputting to wherever WAMP is configured for logging.
     
  9. Rux

    Rux Member

    Joined:
    Mar 9, 2014
    Messages:
    68
    Likes Received:
    32
    Trophy Points:
    58
    I think that was problem with WAMP

    so i started instance on ubuntu 14.04 x64

    I setup everything, dashd started with ./dashd -daemon

    with configured dash.conf
    rpcuser=XXX
    rpcpassword=XXX
    rpcport=8332
    rpcallowip=127.0.0.1
    server=1
    walletnotify=/usr/bin/php -f /srv/app/bin/walletnotify.php %s

    when i want to test with
    php -f walletnotify.php TXID

    it returns me error
    php -f walletnotify.php 3804baab580255f8b24d3ed490741f582d4344d3553e3b59377f97bc0585658fž
    PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /srv/app/bin/walletnotify.php on line 74

    line 74 is
    define('WN_RPC_PORT', '8332');

    Cant figure out, little help for the noob ;D
     
  10. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Can you post the few lines before and after line #74? That error normally means there is a missing semicolon or quote symbol shortly before the line it references.

    Also make sure all of the quotes are normal ' or " quotes. I've seen smart quotes (ie. “ ”) get introduced sometimes which are not valid in code.
     
  11. Rux

    Rux Member

    Joined:
    Mar 9, 2014
    Messages:
    68
    Likes Received:
    32
    Trophy Points:
    58
    //- set for local bitcoind access or remote RPC service like rpc.blockchain.info
    define('WN_RPC_USER', 'XXX');
    define('WN_RPC_PASS', 'XXX');
    define('WN_RPC_HOST',localhost');
    define('WN_RPC_PORT', '8332');
     
  12. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Missing single quote before localhost.
     
  13. Rux

    Rux Member

    Joined:
    Mar 9, 2014
    Messages:
    68
    Likes Received:
    32
    Trophy Points:
    58
    you mean like this? ;)
    define('WN_RPC_HOST','localhost');
     
    #13 Rux, Jun 3, 2015
    Last edited by a moderator: Jun 3, 2015
  14. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Exactly.
     
  15. Rux

    Rux Member

    Joined:
    Mar 9, 2014
    Messages:
    68
    Likes Received:
    32
    Trophy Points:
    58
    ok i did that, now when i start
    [email protected]:/srv/app/bin# php -f walletnotify.php 3804baab580255f8b24d3ed490741f582d4344d3553e3b59377f97bc0585658f

    it returns right away to
    [email protected]:/srv/app/bin#

    but no entry in database :(
     
  16. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Check out the logs.
     
  17. Rux

    Rux Member

    Joined:
    Mar 9, 2014
    Messages:
    68
    Likes Received:
    32
    Trophy Points:
    58
    tail -n10 -f /var/log/apache2/error.log

    i did this but its not showing any recents error logs... but this is for apache, i need php log?

    i really dont know where is it :D
     
  18. Rux

    Rux Member

    Joined:
    Mar 9, 2014
    Messages:
    68
    Likes Received:
    32
    Trophy Points:
    58
    This is my lines for accessing db

    $dsn = 'mysql:dbname=walletnotify;host=localhost';
    $db = new PDO($dsn, 'root', 'password');

    and root user have all privileges on waletnotify database and table

    :) im sorry for bothering you with this, i just wanna learn :D
     
  19. simplebtc

    simplebtc New Member

    Joined:
    Oct 1, 2014
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Yes, you need the PHP log. Depends on versions and how you set it up. Could be log/messages, the Apache error log or even nothing if logging wasn't configured for PHP yet.

    Google is your best friend.

    Once you find where it's logging, add more logging statements as necessary to narrow down what is happening. Even simple line number outputs can be invaluable to see what code is and isn't executing.

    Code:
    error_log('LINE: '.__LINE__);
     
  20. Dxa58

    Dxa58 New Member

    Joined:
    Jun 24, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    If someone could upload their working dash.conf and walletnotify.php I would be really grateful
    My error logs don't indicate any errors but the data isn't being passed to the database