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

243
Vistas
Web3 contract.methods.approve(contractAddress, value), how to prompt user to approve using test account address?

I am able to call Smart contract methods from client machine in development env:

example:

contract.methods.allowance
contract.methods.approve

and I can see the transactions in Ganache UI returned from contract.methods.approve

Which is fine. However, what I am expecting to see in the browser is a prompt in the connected wallet to approve the transaction, similar to the prompt I get when calling:

window.ethereum.request({ method: 'eth_requestAccounts' });

or

window.ethereum.request({ method: 'eth_sendTransaction', params});

The account I am using is one I used provided by Ganache UI where I imported the private key into metamask.

I must be misunderstanding something because there is no point in an "approve" feature conceptually if there is no "approving" taking place by the owner of the address apart from the client machine calling "approve". Does this have something to do with the fact the the dev env already knows what the private key is?

When switching metamask account to an account outside of the development network (my actual account), I get "sender account not recognized" error. But why isn't default behaviour to ask the unrecognised account to approve the transaction?

example, I can call: window.ethereum.request({ method: 'eth_sendTransaction', params}); with the "unrecognised" account and approve the transaction but I can't make a SC call and approve it with this account.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To answer my own question the answer is: Use metamask "window.ethereum" as a provider allowing it to select the network instead of injecting the RPC directly.

I also switched to ethersjs and stopped using web3js. So the following:

const provider = new ethers.providers.Web3Provider(window.ethereum, "any");

Instead of injecting an http provider since the the network doesn't have you private key.

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