Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

298
Vistas
¿Cómo conectarse con la billetera MetaMask en angular uing web3?

Estoy implementando el código en angular para conectarme con la billetera criptográfica al hacer clic en el botón, también instalé web3 pero no sé cómo eliminar el error y usar el código init.

 connectWallet(){ let web3; let ethereum = window.ethereum; if (typeof window.web3 !== 'undefined') { web3 = new Web3(window.web3.currentProvider); } else { web3 = new Web3.providers.HttpProvider(localprovide); } // ethereum = new Web3(window.ethereum); ethereum.enable().then(async (accounts) => { // console.log('transfer called.........', accounts[0]); localStorage.setItem('account', accounts[0]); }); if (window.web3) { // Subscription register ethereum.on('accountsChanged', async (accounts) => { // Reload to avoid MetaMask bug: "MetaMask - RPC Error: Internal JSON-RPC" window.location.reload(); }); window.ethereum.on('networkChanged', async (network) => { window.location.reload(); }); } }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

En el componente de la aplicación OnInit:

 declare const web3: any; declare const Web3: any; public ngOnInit() { if (typeof web3 !== 'undefined') { // Use Mist/MetaMask's provider this.web3Service.web3Instance = new Web3(web3.currentProvider); this.web3Service.initContractInstance(); } else { // Handle the case where the user doesn't have web3. Probably // show them a message telling them to install Metamask in // order to use our app. } }

Servicios Web3:

 @Injectable() export class Web3Service { private contractAddress = "your Contract Address"; public contractInstance: any; public web3Instance: any; public initContractInstance() { this.contractInstance = new this.web3Instance.eth.Contract(ABI, this.contractAddress); } public getAccounts(): Promise<any> { return this.web3Instance.eth.getAccounts() } public signUp(account: string): Promise<any> { return this.contractInstance.methods.signUp() .send({ from: account, value: this.web3Instance.utils.toWei(PRICES.signUp, 'ether') }) } }

En el componente donde desea llamar a algún método que necesita una cuenta:

 export class WelcomeComponent implements OnInit { constructor(private web3Service: Web3Service) { } ngOnInit(): void { } public connectWallet() { if (!ethEnabled()) { console.log("Need to download Wallet") } else { from(this.web3Service.getAccounts()) .subscribe(accounts => { this.web3Service.signUp(accounts[0]) .then(result => { console.log(result) }) }) } } }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda