0

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 1

1

Work in the following order.

  1. Use the USDT contract's approve function to allow the user USDT to be sent to your contract address.
  2. 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.
3
  • 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/… Feb 20, 2021 at 13:31
  • 1
    contract 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.
    – smarteasy
    Feb 20, 2021 at 16:06
  • 1
    My 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? Feb 20, 2021 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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