Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda