Node.js

 
 
Node.js is a server-side software system designed for writing scalable Internet applications, notably web servers.
It is build on built on Chrome's JavaScript runtime. Programs are written on the server side in JavaScript, using event-driven, asynchronous I/O to minimize overhead and maximize scalability.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the web server works. Node.js enables web developers to create an entire web application in JavaScript, both server-side and client-side.

The latest Node.js version can be downloaded from: http://nodejs.org

Even numbered versions (0.4, 0.6, 0.8) are stable, and odd numbered versions (0.3, 0.5) are unstable. The stable releases are API-stable, which means that if you are using 0.8.1 and 0.8.2 comes out, you should be able to upgrade with no issues.







Installing and using bitcoinjs.



Information
More information about bitcoinjs can be found at:
http://bitcoinjs.org/
https://github.com/bitcoinjs/bitcoinjs-lib

Operating system used
Windows Vista Home Premium SP 2

Software prerequisites
Node.js 4.4.5

Procedure
  1. Open a terminal and type: node

  2. Type: console.log("test")

    You should see, for example:
    test
    undefined


  3. To exit the terminal, press: CTRL+C twice.

  4. Install the bitcoinjs-lib.
    Open a terminal and type:npm install bitcoinjs-lib -g

    Install bitcoinjs-lib

  5. Install additional modules, open a terminal:
    • Type: npm install cli-prompt -g
      This module allows you to enter information from the command line.

      Note:
      To check if a module is globally installed, type: npm list cli-prompt -g

    • Type: npm install request -g
      This module allows you to create a simplified HTTP request client.

  6. Below are a number of examples how to use the bitcoinjs library.
    To execute a file, open a terminal and type node <filename>

    No Description Files
    1 Generate 10 Bitcoin private keys and its corresponding public addresses. Store these data in a comma separated file.

    bitcoinjs_example1.js

    Output:
    private_keys.txt

    1b Generate 10 Testnet3 Bitcoin private keys and its corresponding public addresses. Store these data in a comma separated file.

    bitcoinjs_example1b.js

    Output:
    private_keys_testnet.txt

    2 Enter a Bitcoin address and query the blockchain.info response to get the received, sent and total balance of the specified Bitcoin address.

    Note:
    To explore the Bitcoin blockchain, see:
    https://blockchain.info/

    More information about the Blockchain.info API, see: https://blockchain.info/api/blockchain_api

    bitcoinjs_example2.js

    Bitcoin address: 18aiWtmkfVCpoXM7ADj6aRyCfoB6QjsZ3r

    Output:

    Received: 0
    Sent: 0
    Balance: 0
    2b Enter a Testnet3 Bitcoin address and query the blockcypher.com testnet response to get the received, sent and total balance of the specified Bitcoin address.
    Blockchain.info does not provide a Testnet3 block explorer.

    Note 1:
    There are serveral sites where you can get free TestNet3 Bitcoins:
    From faucets several bitcoins were transferred to the Testnet3 Bitcoin address: mhEtqrHsp5UNxVRj4X5zoheShfp782rggs
    See txid:

    2200b8d41504359565ac35d6d0f64b9b
    be5540c4c9b3498b933371347fe04dfc


    Note 2:
    To explore the Testnet3 Bitcoin blockchain, see:
    https://live.blockcypher.com/btc-testnet/

    More information about the Blockcypher.com API, see: http://dev.blockcypher.com/

    bitcoinjs_example2b.js

    Testnet3 Bitcoin address: mhEtqrHsp5UNxVRj4X5zoheShfp782rggs

    Output:

    Received: 12.500000000000000
    Sent: 0
    Balance: 12.500000000000000
    3 Create and send a Bitcoin transaction:
    1. Query for unspent outputs.
    2. Create a transaction were bitcoins (minus fee) are transferred from 1 source address to 1 target address.
    3. Forward the transaction to the Bitcoin network.

    bitcoinjs_example3.js
    3b Create and send a Testnet3 Bitcoin transaction:
    1. Query for unspent outputs.
    2. Create a transaction were bitcoins (minus fee) are transferred from 1 source address to 1 target address.
    3. Forward the transaction to the Testnet3 Bitcoin network.

    Note:
    To explore the Testnet3 Bitcoin blockchain, see:
    https://live.blockcypher.com/btc-testnet/

    More information about the Blockcypher.com API, see: http://dev.blockcypher.com/

    bitcoinjs_example3b.js

    Source Testnet3 Bitcoin address: mhEtqrHsp5UNxVRj4X5zoheShfp782rggs

    Target Testnet3 Bitcoin address: mjkR4541JSBPJotRxFWkY1rwmL68PJ71nX

    Transfer bitcoins (minus fee) from source address to target address, see txid:

    4047443fcb3a7e7d096dd018e780a7b
    f3de06bcae620e48d3b8b7391f905fdf2


    Output:
    bitcoinjs_example3b_output.txt