0

I've been doing a little project of mine where users could donate ether to a certain campaign to reach a certain goal, but I wanted to extend this project a little further and wanted to allow the users to donate multiple ERC20 tokens.

So lets say a user has stated that he only accepts DAI on his campaign but the donor only has WETH on his account.

What do I need to implement in my project to make transactions with ERC20 tokens? (I am asking this because so far I have made simple ETH transactions between two addresses)

How would I swap that WETH for DAI(in this case), and how would I even get those ERC20 tokens to test if its working since I am doing this project on the Rinkeby test net?

I've been reading about the Uniswap Router but I don't know if I could do it on Rinkeby.

0

The uniswap router lives on Rinkeby at the same address it does on mainnet (maybe double check that, but im pretty sure that right). What you're trying to do is create a rather simple smart contract with one function which would accept any token (an token contract address) and amount (an uint) as input, transfer amount of token from the user wallet to the smart contract (using ERC20s transferFrom function), then swap it for the target token (DAI in your case) on the uniswap router using swapExactTokensForTokens ( or maybe swapExactTokensForTokensSupportingFeeOnTransferTokens if you plan on supporting that kind of token), then get its own balance of the target token, and finally send it to the target address

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.