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

208
Views
¿Cómo verificar si una billetera web3 está desbloqueada?

¿Cuál es la mejor práctica para ver si metamask u otras billeteras web3 están desbloqueadas con ethers.js ?

Actualmente uso esto:

 window.ethereum._metamask.isUnlocked()

Pero la documentación de metamask lo informa como métodos experimentales y me gustaría encontrar algo mejor.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Lo que encontró mi experimentación fue que listAccounts devuelve una matriz de cadenas y si la billetera no está desbloqueada, devuelve una matriz vacía.

Para MetaMask específicamente, sé que no puedes tener una cuenta sin tener una dirección.

Por lo tanto, la función que se me ocurrió fue:

 async function isUnlocked() { const provider = new ethers.providers.Web3Provider(window.ethereum); let unlocked; try { const accounts = await provider.listAccounts(); unlocked = accounts.length > 0; } catch (e) { unlocked = false; } return unlocked; }
about 4 years ago · Juan Pablo Isaza Report

0

Esa es mi propia resolución si alguien la necesita:

 isUnlocked$ = new BehaviorSubject<boolean>(false); async isWalletUnlocked() { const web3Provider = new ethers.providers.Web3Provider(window.ethereum, 'any'); const signer = await this.web3Provider.getSigner(); signer .getAddress() .then((address: string) => { this.isUnlocked$.next(true); }) .catch((err) => this.isUnlocked$.next(false)); }
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!