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

96
Views
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 answers
Answer question

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 Report
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!