美文网首页区块链
《区块链项目开发指南》读书笔记4

《区块链项目开发指南》读书笔记4

作者: ytxing | 来源:发表于2018-03-20 11:08 被阅读13次

    第4章 开始使用web3.js

    1. web3.js目前已经到1.0.0-beta18
    2. 接上一章交互控制台继续试验
    console.log(web3.eth.gasPrice.toString());
    

    因为本机刚开始挖矿,gas价格是1

    1. 查看余额(因示例的45区块太大,修改第二个参数“区块”为2)
    console.log(web3.eth.getBalance("0x1628cb0fE5e3fFE930C4Fb13Ba3C0d032DD6cadE",2).toString());
    

    第一个参数是地址

    1. 查看交易细节(无法打印对象,但可以直接输出)
    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
    }
    

    参数为交易号,而非帐户地址。

    1. 章节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);
    

    相关文章

      网友评论

        本文标题:《区块链项目开发指南》读书笔记4

        本文链接:https://www.haomeiwen.com/subject/nwwpqftx.html