6

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

 2 years ago
source link: https://learnblockchain.cn/question/2139
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Solidity当前合约调取一个已部署合约&调取erc20代币合约的方法。无法获取授权额度,导致无法转代币 | 登链社区 | 技术问答

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));
}
}

最佳答案 4天前

0xD1C06084a5eE2B09b215C2A9E564D44581147508 替换为 address(this)

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

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

Tiny熊 - 布道者
擅长:智能合约,以太坊 | 采纳率 41% | 回答于 4天前

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK