The development of Ethereum Wallet 2--Application of WEB3

Source: Internet
Author: User
Tags hash require

In the Ethereum Wallet Development 1, we introduced the node environment building, local blockchain nodes to build and start, the following began to realize the wallet transfer.

In the App.js,

var Web3 = require (' web3 ');
if (typeof web3!== ' undefined ') {
    web3 = new Web3 (web3.currentprovider);
} else {
    //Set the provider you WAN T from web3.providers
    web3 = new Web3 (New Web3.providers.HttpProvider ("http://localhost:8545"));
}

var version = Web3.version.api;
Console.log (version);

We instantiate the Web3 object and use this object to implement all the functions we want.

View Balance

function (Err,result) {
    null) {
        console.log (' ~balance: ' +result);
    } Else   {
        Console.log (' ~error: ' +err);
    }
});

View Deals

Web3.eth.getTransaction (' Transaction hash code ',(err, result) {
    null) {
        Console.log (' Transaction: ' +result);
     {
        console.log (' ERROR: ' +err);
    }
});

Transfer

The ETHEREUMJS-TX module needs to be loaded here:

CD Wallet
NPM Install ETHEREUMJS-TX--save

Tx = require (' Ethereumjs-tx ');
 Buffer (' Wallet account private key ', ' hex '  );
 rawtx = {
    nonce:nonce,
    gasprice: ' 0x3b9aca00 ',
    gaslimit: ' 0x493e0 ', to
    : ' Receiving address ',
    value : ' Amount of money ',
    data: '
};
Tx (rawtx  );
Tx.sign (Privatekey);

 SERIALIZEDTX = Tx.serialize ();
function (Err, hash) {
    Console.log (' Trading results: ' +hash);
     typeof(callback) = = = "function") {
        (!err)
            callback (null, hash);
        Else
 null);}});             

Node App.js//Execute



Later, the development interface for the front-end, mobile use.


Reference: Https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgettransactioncount

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.