以太坊区块链浏览器开发,包括合约信息及链上信息展示,web3j的对应API。
更多区块链技术与应用分类:
一.效果
![以太坊区块链浏览器(二)开发](https://img-blog.csdnimg.cn/img_convert/be3db928aed3762db38de2b5a9ef46b8.png)
二. 合约信息
1.当前用户总数:
$scope.userCount = mxxData.residentCount.call().toString();
2.已分配Token数:
$scope.assingedQuark = mxxQuarkRule.alreadyAssignedAmount.call().toFixed(4);
3.下次分配Token块:
$scope.nextAssingedBlock = mxxQuarkRule.nextAssignQuarkBlock.call().toString() + "(块)";
4. 最近交易块
function updateTXList() {
var currentTXnumber = web3.eth.blockNumber;
$scope.txNumber = currentTXnumber;
$scope.recenttransactions = [];
for (var i=0; i < 10 && currentTXnumber - i >= 0; i++) { //显示十条交易记录
$scope.recenttransactions.push(web3.eth.getTransactionFromBlock(currentTXnumber - i));
}
}
5.最近交易
三. 链信息(ChainInfo)
1.最新块
$scope.blockNum = web3.eth.blockNumber;
var blockNewest = web3.eth.getBlock($scope.blockNum);
2.难度
blockNewest.difficulty;
3.totalDifficultyDividedByDifficulty
$scope.totalDifficultyDividedByDifficulty = $scope.totalDifficulty.dividedBy($scope.difficulty);
4.AltsheetsCoefficient
$scope.AltsheetsCoefficient = $scope.totalDifficultyDividedByDifficulty.dividedBy($scope.blockNum);
5.gasLimit
$scope.gasLimit = blockNewest.gasLimit;
6.格式化的time
var newDate = new Date();
newDate.setTime(blockNewest.timestamp*1000);
$scope.time = newDate.toUTCString();
7.区块链运行时间
$scope.secondsSinceBlock1 = blockNewest.timestamp - 1438226773;
$scope.daysSinceBlock1 = ($scope.secondsSinceBlock1 / 86400).toFixed(2);
8.已出块数
var blockBefore = web3.eth.getBlock($scope.blockNum - 1);
if(blockBefore!==undefined){
$scope.blocktime = blockNewest.timestamp - blockBefore.timestamp;
}
9.最后100块评价出块时间
$scope.range1=100;
range = $scope.range1;//从当前往前数100
var blockPast = web3.eth.getBlock(Math.max($scope.blockNum - range,0));
if(blockBefore!==undefined){
$scope.blocktimeAverage1 = ((blockNewest.timestamp - blockPast.timestamp)/range).toFixed(2);
}
10.整个链出块时间
range = $scope.blockNum;
var blockPast = web3.eth.getBlock(1);
if(blockBefore!==undefined){
$scope.blocktimeAverageAll = ((blockNewest.timestamp - blockPast.timestamp)/range).toFixed(2);
}
11.是否连接(True)
$scope.isConnected = web3.isConnected();
12.API-Client Version:0.12.2 - Geth/v1.8.4-stable/linux-amd64/go1.10
$scope.versionApi = web3.version.api;
$scope.versionClient = web3.version.client;
($scope.versionNetwork = web3.version.network;
$scope.versionCurrency = web3.version.ethereum;)
原文链接:以太坊区块链浏览器(二)开发