How can I use Ethers.js to approve a token on the Frontend

I have been creating a test Dapp but for approvals, I was doing it on Remix
Initially, I was trying to call the approve function from my Smart contract, then It was explained to me why it won't work that way

And someone told me I could do that through the frontend
The ones I have seen on StackOverflow, isn't giving me the exact response I am looking for

My DEX Dapp might not know which token wants to be swapped, so how does it accesses the approval function for that specific token, in order to grant spending rights to my contract?

Aug 30, 2022, 3:23 PM
your dapp must know which token is going to be sold
if I want to sell Token A, the dapp has to take Token A address and call approve() on that contract
so the user will sign the tx
Aug 30, 2022, 3:28 PM
So it has to take the token's contract address to run that function right?
Let me create a code for this
Aug 30, 2022, 3:29 PM
right helfir'e
Aug 30, 2022, 3:29 PM
I was seeing the explanation but I wasn't sure of it
Aug 30, 2022, 3:29 PM
otherwise how can you know what tokens are taken
Aug 30, 2022, 3:30 PM
yes, you need to define a Contract object and call functions to it
Aug 30, 2022, 3:31 PM
But how do I get it's abi?
I think that's the reason I asked the question, it's what I needed to know
Aug 30, 2022, 3:32 PM
if it's a deployed contract, from a blockchain explorer, but it must be verified
if you did the contract, simply from the compiler files or deploy tab on remix
Aug 30, 2022, 3:33 PM
Oh. That's a lot
Considering it actually isn't verified
It's my test tokens
Aug 30, 2022, 3:33 PM
if you're using hardhat, from /artifacts/contracts/yourtoken.sol/yourtoken.json , key "abi"
Aug 30, 2022, 3:34 PM
Or can I create my own custom abi?
Considering all ERC20 tokens follows the same standards?
Aug 30, 2022, 3:34 PM
from remix, compiler tab > compiler details
you can
abi is needed by ethers to know what to say and what to hear back
Aug 30, 2022, 3:34 PM
Custom it is, I guess
Aug 30, 2022, 3:35 PM

© 2024 Draquery.com All rights reserved.