Solidity当前合约调取一个已部署合约&调取erc20代币合约的方法。无法获取授权额度,导致无法转代币

pragma solidity ^0.5.4;
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);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
}

contract test {

IERC20 public lpToken;// = IERC20(0x672E7838C86A6C6b695fb94D1309801A11C5b3DD);

constructor (IERC20 _lpToken) public {
lpToken = _lpToken;
}

function usdtTransfer(uint256 amount) public {
lpToken.approve(address(0x8D5319b98457247822537D424Eb6aF127f7A65cA),amount);
}

function transferUSDT(uint256 amount) public {
lpToken.transfer(0x8D5319b98457247822537D424Eb6aF127f7A65cA, amount);
// lpToken.transferFrom(address(0xD1C06084a5eE2B09b215C2A9E564D44581147508),address(0xF67C37F2Df9754C0aC530aFF9c1fee018c8e3df1),amount);
}

function a() public view returns (uint256 currentAllowance) {
currentAllowance = lpToken.allowance(address(0xD1C06084a5eE2B09b215C2A9E564D44581147508),address(0x8D5319b98457247822537D424Eb6aF127f7A65cA));
}
}
请先 登录 后评论

最佳答案 2021-06-03 15:28

0xD1C06084a5eE2B09b215C2A9E564D44581147508 替换为 address(this)

另外如果你用 transfer 的话, 是不需要 approve 的。

只有当在 目标合约(这里的0x8D5319b98457247822537D424Eb6aF127f7A65cA) 用 transferFrom 时才需要 approve

请先 登录 后评论

其它 1 个回答

livehere
请先 登录 后评论
  • 3 关注
  • 0 收藏,2893 浏览
  • day day up 提出于 2021-06-03 14:48