Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:27
Show Gist options
  • Save percybolmer/40272ecea1a5dbdb3817f54274976ef0 to your computer and use it in GitHub Desktop.
Save percybolmer/40272ecea1a5dbdb3817f54274976ef0 to your computer and use it in GitHub Desktop.
// getABI loads the ABI of the contract
// This is an async function so we can wait for it to finish executing
async function getABI(){
// DevToken.json should be placed inside the public folder so we can reach it
let ABI = "";
await fetch('./DevToken.json', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then((response) => {
// We have a Response, make sure its 200 or throw an error
if (response.status == 200) {
// This is actually also a promise so we need to chain it to grab data
return response.json();
} else {
throw new Error('Error fetching ABI');
}
}).then((data) => {
// We have the data now, set it using the state
ABI = data;
}).catch((error) => {
throw new Error(error);
});
return ABI;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment