关于合约内提现的问题

合约发布的时候定一个owner表示只有合约发布者才能调用提现方法 现在遇到的问题是同样的两个方法 withdrawUsdt() 方法提现USDT就报错,交易失败Revert 但是withdrawTest()这个方法提现就可以成功。 在Nile测试网这俩方法都可以提现成功,主网的话,USDT就不行,有大佬知道什么原因吗? 代码如下:

pragma solidity ^0.5.0;

import "./Token.sol";

contract  Vendor {
    using SafeMath for uint256;
    TRC20  usdt;
    Token  test;

    address private owner;

    constructor(TRC20 _usdt,Token _test) public  {
        usdt = _usdt;
        test = _test;
        owner = msg.sender;

    }

    function withdrawUsdt(uint256 amount) public returns (bool)  {

        require(msg.sender == owner, "Failed to send user balance back to the owner1");

        uint256 ownerBalance = usdt.balanceOf(address(this));

        require(ownerBalance > amount, "Owner has not balance to withdraw");

        (bool sent) = usdt.transfer(msg.sender,amount);
        require(sent, "Failed to send user balance back to the owner2");

        return true;
    }

    function withdrawTest(uint256 amount) public returns (bool)  {

        require(msg.sender == owner, "Failed to send user balance back to the owner1");

        uint256 ownerBalance = test.balanceOf(address(this));

        require(ownerBalance > amount, "Owner has not balance to withdraw");

        (bool sent) = test.transfer(msg.sender,amount);
        require(sent, "Failed to send user balance back to the owner2");

        return true;
    }

}
请先 登录 后评论

最佳答案 2022-05-13 09:06

波场的主网 transfer 里面有返回值, 但是没有return,所以默认都是false...... 所以你判断true一定gg...

eth/trx 两个平台的u,有不同的坑

请先 登录 后评论

其它 0 个回答

  • 0 关注
  • 1 收藏,2286 浏览
  • 萌新 提出于 2022-05-12 18:03