In my smart contract (in moment erc20), is possible create payment function receive eth I would like to receive usdt (or usdc) and not eth, how could I do it? Thanks
1 Answer
Work in the following order.
- Use the USDT contract's approve function to allow the user USDT to be sent to your contract address.
- Write a payment function in your contract. The user calls this function. In the payment function, the USDT corresponding to the payment amount is transferred to your contract.
-
my contract is this, I would like to buy a function with the cost of 1 usdt (require 1usdt), could you show me how to do it? 0bin.net/paste/… Commented Feb 20, 2021 at 13:31
-
1contract USDTPaymentContract { ERC20 usdt; function initialize(address usdt_) external { usdt = ERC20(usdt_); } function payment(uint amount) external { usdt.transferFrom(msg.sender, address(this), amount); } } In initialize, the USDT contract address is passed. Commented Feb 20, 2021 at 16:06
-
1My new contrct is 0bin.net/paste/i2Rqadoy#kETEOOe9NJBLh5nsczx1YvXk-xRhnF/… How can I do to test? Since in the remix I don't have usdt for testing? Commented Feb 20, 2021 at 19:37