Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda