@JohnJohnsss

Почему не получается взять данные из мамассива?

При нажатии на кнопку подключаюсь к кошельку метамаск, после получаю оттуда в переменную accounts массив аккаунтов пользователя, но при попытке создать переменную account = accounts[0], в переменную не получаю значение, а переменная хранит undefined.
if (typeof window.ethereum !== 'undefined') {
  console.log("MetaMask is installed")
} else {
  console.log("MetaMask isn't installed")
  document.querySelector(".enable-eth").innerHTML = '<a href="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn" target="_blank">Install Metamask</a>'
}
const ethBtn = document.querySelector(".enable-eth");
const sendBtn = document.querySelector(".send-eth");
const showAcc = document.querySelector("show-acc");

ethBtn.addEventListener("click", () => {
  getAccount();
  console.log(2121);
});

async function getAccount() {
  /* showAcc.innerHTML = account; */
  const accounts = ethereum.request({ method: 'eth_requestAccounts' })
  let account = accounts[0];
  console.log(accounts)
  console.log(account)
};
  • Вопрос задан
  • 106 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы