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

93
Visualizações
Javascript fetch is invalid name

I have here following JS code to fetch the balance of an ethereum address

async function getBalance() {
  document.getElementById("whoohoo").innerHTML = address;
  const response = await fetch('https://deep-index.moralis.io/api/v2/' + address + '/balance?chain=bsc', {
    method: 'GET',
    headers: ({
      'accept': 'application/json',
      'X-API-Key:': 'api key goes here'
    })
  })
  console.log(await response.json())
}

But instead of getting the balance i get following error:

Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Invalid name
    at <anonymous>:1:876
    at getBalance ((index):38)
    at HTMLButtonElement.login ((index):33)

I assume there is something wrong with the headers but im not quite sure about that. How cvan i fix this?

I have tried to change it to

headers: new Headers({
                    'accept':'application/json',
                    'X-API-Key:':'api key'
                })

and than i get

Uncaught (in promise) TypeError: Failed to construct 'Headers': Invalid name
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try removing the colon from your header:

'X-API-Key:': 'api key goes here'

-->

'X-API-Key': 'api key goes here'
about 4 years ago · Juan Pablo Isaza Relatório
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