Hi all! I am new to solidity and have a few questions.
I have created an ERC20 smart contract that will be used for payment in my application. Now I am creating a second contract which is ERC721. In this contract, I want to make a function that will allow to make a donation in the tokens of the first contract. How can I call the transfer function from the first contract, in the second one?

I tried to access the first contract through the interface and call the transfer function, however, as I understand it, when called, the smart contract itself will be the sender, but I need it to be the address that called the donation method

May 27, 2022, 11:29 AM
So the user (owner of the token) needs to approve the ERC721 contract to transfer their tokens. This is done by the owner calling ERC20.approve(ADDR_OF_ERC721, amount) and then inside donate of ERC721, ERC721 will be able to call ERC20.transferFrom(msg.sender, ADDR_DEST, amount)
May 27, 2022, 12:10 PM
So, it turns out that if a web3 application works with smart contracts, the user will need to confirm two transactions in a row in his metamask?
May 27, 2022, 12:12 PM
Typically, yes. There are permits, but I've never been asked to implement them so I can't explain it exactly. I'm sure there is some documentation on them somewhere.
May 27, 2022, 12:23 PM

© 2024 Draquery.com All rights reserved.