-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch-emerapi.html
88 lines (78 loc) · 2.69 KB
/
fetch-emerapi.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Emercoin API">
<meta name="keywords" content="PrivateNess Network, Emercoin, Skycoin">
<meta name="author" content="JeffBouchard">
<title>GraphQL Query Result</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #FFFFFF;
margin: 0;
padding: 20px;
}
h1{
color: white;
background-color: #367CA5;
padding: 0 2%;
border-radius: 3px;
text-align: center;
}
#result {
max-width: 100%;
overflow-x: auto;
white-space: pre-wrap;
background-color: #F5F5F5;
border-radius: 5px;
padding: 10px;
font-size: 0.9em;
}
button {
background-color: #367CA5;
color: white;
border: none;
border-radius:0.3em;
padding: 10px 20px;
margin-top: 10px;
cursor: pointer;
}
button:active {
background-color: #1B4F73;
}
</style>
</head>
<body>
<h1>GraphQL Query Result</h1>
<div id="result">Click the button to fetch data</div>
<button id="fetchButton">Fetch Data</button>
<script>
document.getElementById('fetchButton').addEventListener('click', function() {
// Display "Loading..." message while fetching data
document.getElementById('result').textContent = 'Loading...';
fetch('https://emerapi.info/graphql', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: 'query { callwalletfunction (method: "getblockchaininfo") { answer } }',
}),
})
.then(res => res.json())
.then(res => {
// Replace "Loading..." with fetched data
document.getElementById('result').textContent = JSON.stringify(res.data, null, 2);
if(res.errors) {
document.getElementById('result').textContent += '\n\nErrors:\n' + JSON.stringify(res.errors, null, 2);
}
})
.catch(err => {
// Display error message
document.getElementById('result').textContent = 'Error:\n' + err;
});
});
</script>
</body>
</html>