Last active
August 6, 2021 11:27
-
-
Save percybolmer/40272ecea1a5dbdb3817f54274976ef0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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