//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
function allowance(address owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
contract contractB {
address tracker_0x_address = 0xaD6D458402F60fD3Bd25163575031ACDce07538D; // Ropsten DAI Address
mapping(address => uint256) public balances;
function deposit(uint256 tokens) public {
// add the deposited tokens into existing balance
balances[msg.sender] += tokens;
// transfer the tokens from the sender to this contract
IERC20(tracker_0x_address).approve(msg.sender, tokens);
IERC20(tracker_0x_address).transferFrom(
msg.sender,
address(this),
tokens
);
}
function balance() public view returns (uint256) {
return IERC20(tracker_0x_address).balanceOf(msg.sender);
}
function returnTokens() public {
balances[msg.sender] = 0;
IERC20(tracker_0x_address).transfer(msg.sender, balances[msg.sender]);
}
}
This is my code and I am not able to transfer DAI to my contract.
I am not able to approve smart contract to spend our DAI
Please help
Thanks in Advance