I created two contracts which are Balance and TempDeposit. In the Balance contract, I wrote Mint function in order to mint certain number of token stored in the contract. Total token minted will be added into minter(msg.sender)'s balance.
Then I called fundNewContract function in TempDeposit contract to transfer user's balance into TempDeposit contract. But I failed to do so and got "Insufficient Amount" error message. The amount that I wanted to transfer to TempDeposit contract is much lower than user's balance in Balance contract. Anyone knows what is the issue here?
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract Balance {
uint public totalSupply;
mapping(address => uint) public balanceOf;
function mint(uint amount) external {
balanceOf[msg.sender] += amount;
totalSupply += amount;
}
function transfer(address _to, uint amount) public {
require(balanceOf[msg.sender] >= amount, "Insufficient Amount");
balanceOf[msg.sender] -= amount;
balanceOf[_to] += amount;
}
function viewBalance(address _address) public view returns (uint) {
return balanceOf[_address];
}
}
contract TempDeposit {
Balance balanceContract;
constructor(address _address) {
balanceContract = Balance(_address);
}
function fundNewContract(uint amount) public {
balanceContract.transfer(address(this), amount);
}
function viewUserBalance(address _address) public view returns(uint) {
return balanceContract.viewBalance(_address);
}
}