here is contract which is interacting with token contract using its token contract address, I dont know what is problem here, first I am allowing account 2 with 1 ether(1*10**18) it is updated in allowance function I shows account 1 have given allowance to account 2 but when I execute transfer function It gives allowance limit exceed error
pragma solidity ^0.8.0;
interface token { //this is interface which will be used
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
contract SampleContract {
token public rup;
address owner;
address public tokenA = 0xb09D706d4FFb546877145481b8ae455CE574838F; // this token is deployed on test-network you can see its balance and other things using ethscan
// address public usdt = 0xdac17f958d2ee523a2206206994597c13d831ec7; // this is real world usdt token address
constructor(){
owner = msg.sender; // saving owner's address
rup = token(tokenA); // this will make all transaction in given address which is defined above(tokenA a test network token)
}
function ApprovalFunds(address to, uint256 amount) public { // first you have to execute this function it will ask from the user
// that this amount of tokens will be set for allowence to owner(which is your address)
rup.approve(to, amount);
}
function TransferFunds(address to, uint256 amount) public { // secound this function will be executed which will transfer funds from current user
// to your account.
rup.transfer(to, amount);
}
function showAllow(address own, address spen) view public returns(uint256) {
return rup.allowance(own, spen);
}
function getBalancee(address addr) view public returns(uint256) {
return rup.balanceOf(addr);
}
}
look at the allowance function output it shows the correct amount but transfer function wont work