current position:Home>Erc20 token not received for contract

Erc20 token not received for contract

2022-02-03 23:54:33 Q & A of Denglian community

I wrote a contract Is to accept erc20 Token , Now? web3 It can be used normally approve To authorize . The authorization is over , Then execute what I wrote in my contract deposit Method , Can't transfer tokens to the contract . What is it for? ? Please teach me . The code is as follows :

interface IERC20 {    function transfer(address recipient, uint256 amount) external;    function balanceOf(address account) external view returns (uint256);    function transferFrom(address sender, address recipient, uint256 amount) external;    function decimals() external view returns (uint8);}contract usdtCharge {    /* Variable declarations  */    IERC20 usdt;    struct Player {        uint256 total_charge;        uint256 total_withdrawn;    }    address payable public owner;    address payable public main_addr;    mapping(address => Player) public players;    /* Contract construction class */    constructor(address payable _addr,IERC20 _usdt) public {        owner = msg.sender;        main_addr = _addr;        usdt = _usdt;    }    /* Deposit operation */    function deposit(address fromAddr,uint _usdtAmount) external {        Player storage player = players[msg.sender];        usdt.transferFrom(fromAddr,address(this), _usdtAmount);        player.total_charge = _usdtAmount;    }    /* Withdrawal operation */    function withdraw(address _target, uint256 _amount) external {        if(msg.sender != main_addr){            Player storage player = players[_target];            player.total_withdrawn += _amount;            usdt.transfer(_target, _amount);        }    }}





Other answers 1:

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032354305336.html

Random recommended