Hey everyone🖖🏼 I am trying to deposit a DAI token into a smart contract deployed on polygon mumbai network. I swapped matic tokens for DAI on Quickswap, found the address of this DAI token and want the user to store these tokens in smart contract.

Mar 31, 2022, 7:48 AM
I am a little bit confused what is supposed to be the units of daiAmount in this case. Is it WEI or ETH(dai) ?
I wanna send 0.5 DAI so I am sending it in wei and getting an error, what is wrong here ?
And I am getting this when I try to call the function
Mar 31, 2022, 7:49 AM
you can't approve from a third party contract
when the contract call the approve method on DAI contract, the msg.sender will be your contract address not your address
tl;dr

you can't approve + transfer in 1 tx

not with erc20
Mar 31, 2022, 8:02 AM
okay, but even if I try using another address it still doesn’t work
Mar 31, 2022, 8:53 AM
you didn't understand
.
.
Mar 31, 2022, 8:53 AM
oh so you mean I shouldn’t approve and tranferFrom in one function?
if so, how do I implement this logic of depositing DAI into smart contract ?
Mar 31, 2022, 8:55 AM
you can't call approve from a third party contract if you want that the user approve the DAI
or you make a dapp where you add a button that call the approve method on the dai, with user connected with wallet

or you tell the user to manually call the approve on DAI contract passing your contract address as first argument
Mar 31, 2022, 8:57 AM
okay thx, got it
Mar 31, 2022, 9:22 AM
You have approved address(this) not the msg.sender
Mar 31, 2022, 9:22 AM
I figured how to approve but still getting an error when tryin to call this function that deposits DAI
I suppose it might be a problem with units conversion
but what is excatly wrong here?
Mar 31, 2022, 9:57 AM
I think there is error in approve. You need approve 'contract' to spend your tokens, not acc[0]
Mar 31, 2022, 10:03 AM
Did you see the link it tells you to check?
Mar 31, 2022, 10:07 AM
yeah, that’s right 🙂 thank you
Mar 31, 2022, 10:09 AM
it is
Mar 31, 2022, 11:09 AM

© 2024 Draquery.com All rights reserved.