This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiQuerys.js
90 lines (77 loc) · 2.99 KB
/
apiQuerys.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
https://v1.cosmos.network/rpc/v0.45.1
Cosmos SDK v0.45.1 (Gaia v7.0.0 / cosmoshub-4)
cosmosvaloper1r2dthxctqzhwg299e7aaeqwfkgcc9hg8k3yd7m
*/
var api = {
staking: {
getAllPendingStakingRewards: async function(address){
return fetch(`https://api.cosmos.network/cosmos/distribution/v1beta1/delegators/${address}/rewards`)
.then((response) => response.json())
.then((data) => {return data})
.catch((e) => console.error(e))
},
getAllDelegations: async function(address){
return fetch(`https://api.cosmos.network/cosmos/staking/v1beta1/delegations/${address}`)
.then((response) => response.json())
.then((data) => {return data.delegation_responses})
.catch((e) => console.error(e))
},
getAllUsingValidators: async function(address){
return fetch(`https://api.cosmos.network/cosmos/distribution/v1beta1/delegators/${address}/validators`)
.then((response) => response.json())
.then((data) => {return data})
.catch((e) => console.error(e))
},
getValidatorInfo: async function(address){
return fetch(`https://api.cosmos.network/staking/validators/${address}`) //old API
.then((response) => response.json())
.then((data) => {return data})
.catch((e) => console.error(e))
}
},
bank: {
getAllBalances: async function(address){
return fetch(`https://api.cosmos.network/bank/balances/${address}`)
.then((response) => response.json())
.then((data) => {
return data.result
})
.catch((e) => console.error(e))
},
getBalance: async function(address, denom){
return this.getAllBalances(address)
.then((balances) => {
for (const balance of balances) {
if(balance.denom === denom){
return balance.amount
}
}
console.error(`coin with denom: ${denom} has not been found`)
})
},
},
global: {
getInflation: async function(){
return fetch(`https://api.cosmos.network/cosmos/mint/v1beta1/inflation`)
.then((response) => response.json())
.then((data) => {return data})
.catch((e) => console.error(e))
},
getBondedTokenRatio: async function(){
return fetch(`https://api.cosmos.network/cosmos/mint/v1beta1/params`)
.then((response) => response.json())
.then((data) => {return data})
.catch((e) => console.error(e))
}
}
}
export {api};
/*
APY
Staking Fee
Staked
Pending Staking Reward
annual provisons: 38498735811762.946698919331052078
https://api.cosmos.network/cosmos/mint/v1beta1/annual_provisions
*/