Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Returning a variable from another async function in Javascript returns undefined

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)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!