Explore Sanbase Demo
Example of usage Sanbase Graphql API.
by Zatcepin
HTML
<!-- Include the library in the page -->
<script src="https://unpkg.com/[email protected]"></script>
<!-- App -->
<div id="app">
<h1>Explore Sanbase Demo</h1>
<div>
<div id="result" class="loading">Loading... </div>
</div>
</div>
CSS
body {
font-family: sans-serif;
margin: 0;
background: #f0f0f0;
}
#app {
padding: 24px;
max-width: 400px;
margin: auto;
}
h1 {
text-align: center;
font-weight: normal;
font-size: 18px;
}
.loading {
text-align: center;
color: #777;
}
JavaScript
console.clear()
const client = new Apollo.lib.ApolloClient({
networkInterface: Apollo.lib.createNetworkInterface({
uri: 'https://sanbase-low.santiment.net/graphql',
transportBatching: true,
}),
connectToDevTools: true,
})
const QUERY = Apollo.gql`
{
allProjects {
name
ethBalance
}
}
`
client.query({ query: QUERY}).then(result => {
const balance = result.data.allProjects.reduce((acc, val) => {
return acc = +val.ethBalance + acc
}, 0)
resultEl = document.querySelector('#result')
resultEl.innerHTML = "All Projects balance is ETH " + balance.toFixed(2)
})