cnpm install [email protected] --save-dev
cnpm list web3
if(typedef web3 !== 'undefined'){
web3 == new Web3(web3.currentProvider);
}else{
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
web3.eth.getBlock(48,function(error,result)){
if(!error)
console.log(JSON.stringify(result));
else
console.error(error);
}
[
{
"constant":true,
"inputs":[
{
"name":"",
"type":"address"
}
],
"name":"balances",
"outputs":[
{
"name":"",
"type":"uint256"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
},
{
"constant":true,
"inputs":[
],
"name":"miner",
"outputs":[
{
"name":"",
"type":"address"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
},
{
"constant":false,
"inputs":[
{
"name":"receiver",
"type":"address"
},
{
"name":"amount",
"type":"uint256"
}
],
"name":"mint",
"outputs":[
],
"payable":false,
"stateMutability":"nonpayable",
"type":"function"
},
{
"constant":false,
"inputs":[
{
"name":"receiver",
"type":"address"
},
{
"name":"amount",
"type":"uint256"
}
],
"name":"send",
"outputs":[
],
"payable":false,
"stateMutability":"nonpayable",
"type":"function"
},
{
"inputs":[
],
"payable":false,
"stateMutability":"nonpayable",
"type":"constructor"
},
{
"anonymous":false,
"inputs":[
{
"indexed":false,
"name":"from",
"type":"address"
},
{
"indexed":false,
"name":"to",
"type":"address"
},
{
"indexed":false,
"name":"amount",
"type":"uint256"
}
],
"name":"Sent",
"type":"event"
}
]
var BigNumber = require('bignumber.js')
var balance = new BigNumber('1231231231123325647673565363777373733833222');
balance.plus(21).tostring(10);//或者直接输入balance就可以,tostring(位数)转化进制
//s表示正负数,1表示正数,-1表示负数
//e表示科学技法中的10的位数
//c数组,每14位切割一次定义成数组