Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda