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

233
Views
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 answers
Answer question

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 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!