I’m building an extension for myself, so I can add Ethereum or BNB wallets and see their balances. But when I put the wallet and press “Add”, I get errors that I don’t know how to solve anymore.
At first I was getting an API error, then I don’t get any more, but now I get these two errors:
I leave the complete JSON:
const walletForm = document.getElementById("walletForm");
const walletAddress = document.getElementById("walletAddress");
const totalBalance = document.getElementById("totalBalance");
const walletList = document.getElementById("walletList");
walletForm.addEventListener("submit", (e) => {
e.preventDefault();
const address = walletAddress.value.trim();
if (address) {
addWallet(address);
}
walletAddress.value = "";
});
const ETHERSCAN_API_KEY = "FAKEAPI";
const BSCSCAN_API_KEY = "FAKEAPI";
async function addWallet(address) {
try {
const ethereumBalance = await getEthereumBalance(address);
const bnbBalance = await getBNBBalance(address);
// Resto del código para agregar la billetera
} catch (error) {
console.error(`Error en la función addWallet: ${error.message}`);
}
}
async function getEthereumBalance(address) {
try {
const response = await fetch(`https://api.etherscan.io/api?module=account&action=balance&address=${address}&tag=latest&apikey=FAKEAPI`);
if (!response.ok) {
throw new Error(`Error en la respuesta de la API: ${response.statusText}`);
}
const data = await response.json();
if (data.message === 'OK') {
console.log(`Resultado de la llamada de API: ${data.result}`);
return BigInt(data.result);
} else {
throw new Error(`Error en la respuesta de la API: ${data.message}`);
}
} catch (error) {
console.error(`Error en la función getEthereumBalance: ${error.message}`);
return null;
}
}
async function getBNBBalance(address) {
try {
const response = await fetch(`https://api.bscscan.com/api?module=account&action=balance&address=${address}&tag=latest&apikey=D96DAB88GRZY5UZ3YFJSZMUVA6E5H8EMU8`);
if (!response.ok) {
throw new Error(`Error en la respuesta de la API: ${response.statusText}`);
}
const data = await response.json();
if (data.message === 'OK') {
console.log(`Resultado de la llamada de API: ${data.result}`);
return BigInt(data.result);
} else {
throw new Error(`Error en la respuesta de la API: ${data.message}`);
}
} catch (error) {
console.error(`Error en la función getBNBBalance: ${error.message}`);
return null;
}
}
Its just an extension, why is so hard? I feel the problem in the API code, but.. I dont knok.