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