current position:Home>Why is the transfer authorization unsuccessful

Why is the transfer authorization unsuccessful

2022-02-03 22:59:25 Q & A of Denglian community

pragma solidity ^0.6.0;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);}contract  MyContract {     IERC20 usdt;  constructor(IERC20 _usdt) public  {           usdt = _usdt;      }  function transferOut(address toAddr, uint amount) external {    usdt.transfer(toAddr, amount);  }  function transferIn(address fromAddr, uint amount) external {    // bytes4 methodId = bytes4(keccak256("transferFrom(address,address,uint256)"));    // address(usdt).delegatecall(abi.encode(methodId,froamAddr,address(this), amount));    address(usdt).delegatecall(abi.encodeWithSignature("transferFrom(address,address,uint256)",fromAddr,address(this), amount));  }  function approve (uint256 amount) external{    // bytes4 methodId = bytes4(keccak256("approve(address,uint256)"));    // (r, s) = logicContractAddr.delegatecall(abi.encodeWithSignature("test(address)", this));    address(usdt).delegatecall(abi.encodeWithSignature("approve(address,uint256)",address(this), amount));  }}

Take the answer 1:

Add Last question

It's not suitable to use delegatecall , delegatecall Modify the status of the transferred contract , Reference resources Solidity file

If user authorization is required , You need to use Web3.js To enable users to initiate Authorization ( Use web3.js call approve).

And in the contract A Authorization in means : Authorize others to use A Coins .

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.

Random recommended