合约发布的时候定一个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;
}
}