I'm trying to run a function that sets up a bunch of things for my code. The first thing is getting a JSON object from an api to use later. When I run the code and console log the abi in the getAbi function, it logs out the JSON.
When I do the same thing from another function it returns undefined.
How can I fix this? I assume it's because the code is running before its returned, but I can't figure out how to get it in order.
async function getAbi (contract) {
if (config['abi'] != ""){
abi = config['abi']
return abi
}else {
request('https://api.etherscan.com/api?module=contract&action=getabi&address='+ contract + '&apikey=' + bscScanToken, async (err, response, body) => {
if (err) {
console.log(err)
} else{
body = JSON.parse(body)
abi = body.result
return abi
}
})
}
}
async function setupMint() {
abi = await getAbi(contract)
console.log(abi)