Skip to content

Instantly share code, notes, and snippets.

@ponyjackal
Created August 5, 2021 12:48
Show Gist options
  • Save ponyjackal/bd119598e7dbd92be361902f951481e9 to your computer and use it in GitHub Desktop.
Save ponyjackal/bd119598e7dbd92be361902f951481e9 to your computer and use it in GitHub Desktop.
Querying Blockchain Data with GraphQL from a Web Application with URQL and The Graph
import './App.css';
import { createClient } from 'urql'
import { useEffect, useState } from 'react'
const APIURL = ""
const query = `
query {
tokens(
first: 5
orderBy: tokenID
orderDirection:desc
) {
id
tokenID
contentURI
metadataURI
}
}
`
const client = createClient({
url: APIURL
})
function App() {
const [tokens, setTokens] = useState([])
useEffect(() => {
fetchData()
}, [])
async function fetchData() {
const response = await client.query(query).toPromise();
console.log('response:', response)
setTokens(response.data.tokens);
}
return (
<div className="App">
{
tokens.map((token, index) => (
<div>
<a href={token.contentURI} target="_blank">Content</a>
<a href={token.metadataURI} target="_blank">Metadata</a>
</div>
))
}
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment