/**\t\t * 查询区块信息\t\t * @return {@link Map<String,Object>}\t\t * @author dapp\t\t */\t\t@RequestMapping(value="/getBlockInformation",method= RequestMethod.POST)\t\t@ResponseBody\t\tpublic Map<String,Object> getBlockInformation(){\t\t\tMap<String,Object> resultMap = new HashMap<>(16);\t\t\ttry {\t\t\t\t// 连接以太坊客户端\t\t\t\tWeb3j web3j = Web3j.build(new HttpService("http://{获取区块链所在服务器ip}:8545"));\t\t\t\tEthBlock block = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send();\t\t\t\tSystem.out.println("查询结果--区块高度:"+block.getBlock().getNumber());\t\t\t\tSystem.out.println("查询结果--区块Hash:"+block.getBlock().getHash());\t\t\t\tresultMap.put("success",true);\t\t\t\tresultMap.put("data",null);\t\t\t}catch (Exception e){\t\t\t\tresultMap.put("success",false);\t\t\t\tresultMap.put("message","查询失败");\t\t\t\tlog.error("查询失败",e);\t\t\t}\t\t\treturn resultMap;\t\t}

区块链查询API - 获取最新区块信息

原文地址: https://www.cveoy.top/t/topic/pE3q 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录