开发以太坊遇到的几个问题

1.数据同步(根据帐号查询历史交易信息)

https://ethereum.stackexchange.com/questions/2531/common-useful-javascript-snippets-for-geth/3478#3478

 

function getTransactionsByAccount(myaccount, startBlockNumber, endBlockNumber) {
  if (endBlockNumber == null) {
    endBlockNumber = eth.blockNumber;
    console.log("Using endBlockNumber: " + endBlockNumber);
  }
  if (startBlockNumber == null) {
    startBlockNumber = endBlockNumber - 1000;
    console.log("Using startBlockNumber: " + startBlockNumber);
  }
  console.log("Searching for transactions to/from account \"" + myaccount + "\" within blocks "  + startBlockNumber + " and " + endBlockNumber);

  for (var i = startBlockNumber; i <= endBlockNumber; i++) {
    if (i % 1000 == 0) {
      console.log("Searching block " + i);
    }
    var block = eth.getBlock(i, true);
    if (block != null && block.transactions != null) {
      block.transactions.forEach( function(e) {
        if (myaccount == "*" || myaccount == e.from || myaccount == e.to) {
          console.log("  tx hash          : " + e.hash + "\n"
            + "   nonce           : " + e.nonce + "\n"
            + "   blockHash       : " + e.blockHash + "\n"
            + "   blockNumber     : " + e.blockNumber + "\n"
            + "   transactionIndex: " + e.transactionIndex + "\n"
            + "   from            : " + e.from + "\n" 
            + "   to              : " + e.to + "\n"
            + "   value           : " + e.value + "\n"
            + "   time            : " + block.timestamp + " " + new Date(block.timestamp * 1000).toGMTString() + "\n"
            + "   gasPrice        : " + e.gasPrice + "\n"
            + "   gas             : " + e.gas + "\n"
            + "   input           : " + e.input);
        }
      })
    }
  }
}

 

Example

Find transactions to/from eth.accounts[0] address:

> getTransactionsByAccount(eth.accounts[0])
Using endBlockNumber: 1864
Using startBlockNumber: 864
Searching for transactions to/from account "0xa7857047907d53a2e494d5f311b4b586dc6a96d2" within blocks 864 and 1864
Searching block 1000
  tx hash          : 0x3c3bc3c456a84e20cf0077f9aa5ce363d3b12bca18d01000a750288c2e76401e
   nonce           : 44
   blockHash       : 0xef2d15775908951fc61f9a83b53c00cf2cde4e0def93e20544f784441c6178db
   blockNumber     : 1582
   transactionIndex: 0
   from            : 0xa7857047907d53a2e494d5f311b4b586dc6a96d2
   to              : null
   value           : 0
   time            : 1470459255 Sat, 06 Aug 2016 04:54:15 GMT
   gasPrice        : 20000000000
   gas             : 24615
   input           : 0x6060604052600a8060106000396000f360606040526008565b00
  tx hash          : 0xc255cdbf477452eb8922d8230889f7cc08b9deed4695378aba3d97906071ce5f
   nonce           : 45
   blockHash       : 0x987a8214af96bb1530b97fe09da8f8168679e42c9efb4defee50800f2067d6d8
   blockNumber     : 1587
   transactionIndex: 0
   from            : 0xa7857047907d53a2e494d5f311b4b586dc6a96d2
   to              : null
   value           : 0
   time            : 1470459409 Sat, 06 Aug 2016 04:56:49 GMT
   gasPrice        : 20000000000
   gas             : 24615
   input           : 0x6060604052600a8060106000396000f360606040526008565b00
...

 

 

2.根据交易hash查询raw数据

https://ethereum.stackexchange.com/questions/7473/get-raw-transaction-from-hash

 

There is an "undocumented" method eth_getRawTransactionByHash from JSON-RPC

curl -H "Content-Type: application/json" -X POST --data \
'{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":[""],"id":1}' http://localhost:8545

- transaction id

curl -H "Content-Type: application/json" -X POST --data \'{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":[""],"id":1}' http://localhost:8545

请查看我的另一篇文章

http://mp.blog.csdn.net/postedit/79428665

3.交易状态的确定  

out of gas

https://etherscan.io/tx/0xaee761811a9d4957faca2e01eaea806e0de9c738f91b1fb8c9e1f963a7c3a506

解决办法

https://ethereum.stackexchange.com/questions/23204/how-can-i-tell-from-raw-transaction-data-if-it-succeeded-or-failed

主要思路是

web3.eth.getTransactionReceipt 返回的

status 

如果没有就比较

web3.eth.getTransactionReceipt

gasUsed

web3.eth.getTransaction

 

gas

4.geth 节点同步总追不上

尤其到2400000后,追的这个费劲

电脑性能硬伤,这个不考虑

星火计划

https://ethfans.org/wikis/Home

加入个static-nodes.json 文件到

--datadir "/data/geth/" /data/geth/ 里

1.6以上版本geth默认 fast 模式同步 启动需加

--syncmode fast --maxpeers 100

--cache 2048

都是扯淡(阿里租个服务器SSD,几天就同步完成())

 5.ERC20 tx

ERC20代币及属性

https://github.com/kvhnuke/etherwallet/blob/mercury/app/scripts/tokens/ethTokens.json

交易特殊to 的地址是合约地址,需另解析to ,input 

6.gas price

https://ethgasstation.info

 

 

你可能感兴趣的:(区块链)