0

I'm working in remix and I deployed BUSD contract and I want use it's functions. I wrote a contract and I want to use it to users approve the contract here's my code

pragma solidity 0.8.14;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
contract test{
    address private token = address(0x26b989b9525Bb775C8DEDf70FeE40C36B397CE67);
    IERC20 mytoken = IERC20(token);
function approvetest(uint amount) public{
    token.delegatecall(abi.encodeWithSignature("approve(address,uint256)", address(this), amount));
}

}

in the output it returns these:

"owner": "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4",
"spender": "0x8B801270f3e02eA2AACCf134333D5E5A019eFf42",
"value": "10000000000000000000"

and it's correct owner is me and spender is contract address but when I call allowance function in token contract it returns 0. and I can't use "transferFrom" because it returns error

BEP20: transfer amount exceeds allowance

what is the problem?

Meysam
  • 81
  • 8
  • You cannot use delegate calls like that. Check this answer. You have to directly call the BUSD or token contract for approve. – Krishna Kumar S Jul 26 '22 at 13:29
  • hi if i dont use delegate call the token contract will use my contract address as msg.sender. what is you suggestion? – Meysam Jul 26 '22 at 13:41
  • i meant, this should be called directly from the frontend using web3.js/ethers.js – Krishna Kumar S Jul 26 '22 at 13:44
  • i want to do approve and transferFrom function in one transaction if I use frontend to directly call token contract that would be two transaction – Meysam Jul 26 '22 at 13:47
  • I understood, but that is not possible. Check the link that I put on the first comment. I think you might want to use a different ERC standard. – Krishna Kumar S Jul 26 '22 at 14:07

0 Answers0