开发以太坊遇到的几个问题
2018-03-02 17:41
309 查看
1.数据同步(根据帐号查询历史交易信息) https://ethereum.stackexchange.com/questions/2531/common-useful-javascript-snippets-for-geth/3478#3478
2.根据交易hash查询raw数据 https://ethereum.stackexchange.com/questions/7473/get-raw-transaction-from-hash
There is an "undocumented" method
http://mp.blog.csdn.net/postedit/79428665
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/frometh.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_getRawTransactionByHashfrom JSON-RPC
curl -H "Content-Type: application/json" -X POST --data \ '{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":["<TX_HASH>"],"id":1}' http://localhost:8545<TX_HASH> - transaction idcurl -H "Content-Type: application/json" -X POST --data \'{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":["<TX_HASH>"],"id":1}' http://localhost:8545 请查看我的另一篇文章
http://mp.blog.csdn.net/postedit/79428665
相关文章推荐
- 贴吧系统开发中遇到的几个问题——数据传输限制
- 今天跟新AS和NDK开发遇到几个很骚的问题
- Web开发基础--WebService调试过程中遇到的几个问题
- ubuntu上搭建eclipse下hadoop-2.7.1集群(全分布式)开发环境遇到的几个问题笔记
- IOS应用内购买(IAP)开发时遇到的几个问题总结
- jsp开发遇到的几个问题与解决办法
- 开发QQ互联android版Ane扩展 遇到几个典型问题
- Android开发新手会遇到的几个问题
- 开发自动完成功能中遇到的几个问题---javascript+XMLHTTP+DOM
- WebSocket开发过程中遇到的几个小问题
- 开发中遇到的几个问题
- 重新搭建"灶具维修管理系统"的VB开发环境遇到的几个问题
- [Windows通用应用开发] 代码编写StoryBoard时可能遇到的几个问题
- 2016年7月19日开发android遇到的几个问题
- cocos2d-x开发遇到的几个问题
- 拿什么拯救:Android Studio 时代 继续使用Eclipse开发Android app时遇到的几个问题以及解决办法
- 几个Android开发中遇到的问题
- iphone 开发中使用zbar时遇到的几个典型问题解决方法。
- 【问题记录】近期开发中遇到的几个问题
- JSP开发中遇到的几个小问题