Below is my solidity code. I am trying to send MATIC to the "receiverAddress". Everything looks fine. I have 2.3875 MATIC in my wallet and I'm inserting 87500000000000000 as sending MATIC value. But after the transaction completed no MATIC is dropping from my wallet and none is sent to the "receiverAddress". What is wrong in my function?
Here is the transaction details on Polygonscan Mumbai: https://mumbai.polygonscan.com/tx/0x2b67e379f3117fe5a05242339588a8113bd923fe40106e676db8199a64787f7a
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract MaticTransfer {
address public constant receiverAddress = 0x7d55273b60BEc66895f547515256E092f31c61B8;
address public owner;
IERC20 public maticToken;
constructor(address _maticTokenAddress) {
owner = msg.sender;
maticToken = IERC20(_maticTokenAddress);
}
modifier onlyOwner() {
require(msg.sender == owner, "Only the contract owner can call this function");
_;
}
function transferMatic(uint256 _amount) public payable {
require(_amount > 0, "Amount should be greater than zero");
uint256 balance = maticToken.balanceOf(address(this));
require(balance <= _amount, "Insufficient balance in the contract");
maticToken.transfer(receiverAddress, _amount);
}
function getContractBalance() external view returns (uint256) {
return maticToken.balanceOf(address(this));
}
}
Update:
When I entered the value at "1" it droped the MATIC from my wallet. I was trying to enter at "2". But it is not received from "receiverAddress". Where did that MATIC go? If it is on smartcontract how we can make this to send to the wallet?