第4章 開始使用web3.js
- web3.js目前已經(jīng)到1.0.0-beta18
- 接上一章交互控制臺繼續(xù)試驗
console.log(web3.eth.gasPrice.toString());
因為本機剛開始挖礦忘古,gas價格是1
- 查看余額(因示例的45區(qū)塊太大佛玄,修改第二個參數(shù)“區(qū)塊”為2)
console.log(web3.eth.getBalance("0x1628cb0fE5e3fFE930C4Fb13Ba3C0d032DD6cadE",2).toString());
第一個參數(shù)是地址
- 查看交易細節(jié)(無法打印對象青责,但可以直接輸出)
web3.eth.getTransactionReceipt("0x3fc10b7326cc5f4211ac6c665c3370b2d00a1b433659cfb1e48da8d0b884ae01");
輸出類似如下形式
{
blockHash: "0x47c72a27d214838de126ca4057e5760ae45ab5e285104eddde2b9b958646938a",
blockNumber: 1,
contractAddress: "0xf095b1932ee9e6424b328bdf518d617503c7c0f7",
cumulativeGasUsed: 574693,
from: "0x1628cb0fe5e3ffe930c4fb13ba3c0d032dd6cade",
gasUsed: 574693,
logs: [],
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
status: "0x1",
to: null,
transactionHash: "0x3fc10b7326cc5f4211ac6c665c3370b2d00a1b433659cfb1e48da8d0b884ae01",
transactionIndex: 0
}
參數(shù)為交易號,而非帳戶地址习瑰。
- 章節(jié)4.1.9的程序代碼琼懊,感謝簡述的Solidity高亮
var event = proof.logFileAddedStatus(null, {
fromBlock: 0,
toBlock:"latest"
});
event.get(function(error, result){
if(!error)
{
console.log(result);
}
else
{
console.log(error);
}
});
event.watch(function(error, result){
if(!error)
{
console.log(result.args.status);
}
else
{
console.log(error);
}
});
setTimeout(function(){
event.stopWatching();
}, 60000);
var events = proof.allEvents({
fromBlock: 0,
toBlock: "latest"
});
events.get(function(error, result){
if(!error)
{
console.log(result);
}
else
{
console.log(error);
}
});
event.watch(function(error, result){
if(!error)
{
console.log(result.args.status);
}
else
{
console.log(error);
}
});
setTimeout(function(){
event.stopWatching();
}, 60000);