Hi. I've got a basic contract that all features work on except the deposit into the contract. The problem is I don't get any error information from Remix when I execute the depositTokenAmount function. So not sure how to debug it or figure out what is wrong?
Testnet Steps:
- Load wallet with 100000000 USDC ($100.00)
- Execute getTokenBalance -> 0. Successful
- Execute approveTokenAmount with 1000000 ($1.00). Successful
- Execute depositTokenAmount with 500000 ($0.50). Failed. No error generated.
- Scratch head.
creation of Test pending...
[block:214904075 txIndex:-]
from: 0xf60...70283
to: Test.(constructor)
value: 0 wei
data: 0x608...90033
logs: 0
hash: 0x4c1...1772d
Debug
call to Test.getTokenBalance
*CALL* [call]
from: 0xf6087795a815ef9d9ebac667ada2600469c70283
to: Test.getTokenBalance(address)
data: 0x3ae...e5831
Debug
transact to Test.approveTokenAmount pending ...
[block:214904077 txIndex:-]
from: 0xf60...70283
to: Test.approveTokenAmount(address,uint256) 0x059...137da
value: 0 wei
data: 0x255...f4240
logs: 1
hash: 0x256...3b357
Debug
transact to Test.depositTokenAmount pending ...
[block:214904078 txIndex:-]
from: 0xf60...70283
to: Test.depositTokenAmount(address,uint256) 0x059...137da
value: 0 wei
data: 0x818...f4240
logs: 0
hash: 0x6c4...ecf01
Debug
|status|0x0 Transaction mined but execution failed|
| --- | --- |
|transaction hash|0xb6a005889ddb64dda4c6ae96a7c1381f323c71975709ac5719a6f578c25f9734|
|block hash|0x6c44290320ef1f23126e41e1287c42b062c0b7846bd1d566cf983ff55c3ecf01|
|block number|214904078|
|from|0xf6087795a815ef9d9ebac667ada2600469c70283|
|to|Test.depositTokenAmount(address,uint256) 0x059f4c4ecde9a555b6bc59c748908138a09137da|
|gas|999000 gas|
|transaction cost|37921 gas|
|input|0x818...f4240|
|decoded input|{ "address _tokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", "uint256 _amount": "1000000" }|
|decoded output|-|
|logs|[]|
Contract:
// contracts/Test.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol';
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol';
contract Test {
address payable owner;
constructor()
{
owner = payable(msg.sender);
}
/**
Testing basic ERC20 token functions.
*/
function getTokenBalance(
address _tokenAddress
) external view returns (uint256) {
return IERC20(_tokenAddress).balanceOf(address(this));
}
function approveTokenAmount(
address _tokenAddress,
uint256 _amount
) external onlyOwner {
IERC20(_tokenAddress).approve(msg.sender, _amount);
}
function depositTokenAmount(
address _tokenAddress,
uint256 _amount
) external onlyOwner {
IERC20 token = IERC20(_tokenAddress);
uint256 allowance = token.allowance(
msg.sender,
address(this)
);
require(allowance >= _amount, 'msg.sender allowance too low.');
token.transferFrom(
msg.sender,
address(this),
_amount
);
}
function withdrawTokenBalance(
address _tokenAddress
) external onlyOwner {
IERC20(_tokenAddress).transfer(
msg.sender,
IERC20(_tokenAddress).balanceOf(address(this))
);
}
modifier onlyOwner() {
require(
msg.sender == owner,
"Only the contract owner can call this function"
);
_;
}
receive() external payable {}
}