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
Try removing the colon from your header:
'X-API-Key:': 'api key goes here'
-->
'X-API-Key': 'api key goes here'