'Can't transfer Matic to smart contract

I'm trying to transfer Matic to my smart contract in the Mumbai test net using ethers.

I'm using the most basic contract which comes with hardhat - Greeter. sol.

The error I keep getting is(in the polygonscan-mumbai): enter image description here

The client side transfer using ethers:

const provider = new ethers.providers.Web3Provider(ethereum);
const signer = provider.getSigner();
const erc20Contract = new ethers.Contract("0x0000000000000000000000000000000000001010", erc20abi, signer);
const parsedAmount = ethers.utils.parseUnits(amount.toString(), 'ether');
const transferTokens = await erc20Contract.transfer(contractAddress , parsedAmount);

Greeter.sol:

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "hardhat/console.sol";

contract Greeter {
    string private greeting;

    constructor(string memory _greeting) {
        console.log("Deploying a Greeter with greeting:", _greeting);
        greeting = _greeting;
    }

    function greet() public view returns (string memory) {
        return greeting;
    }

    function setGreeting(string memory _greeting) public {
        console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
        greeting = _greeting;
    }
}

Also when I manually try to send Matic to the smart contract using metamsk it's giving me the same error(only to contracts, not other wallets). But if I try other tokens it works fine - am I missing something?



Solution 1:[1]

Your contract needs to implement either receive() or fallback() function to be able to accept native currency of the network.

Docs: https://docs.soliditylang.org/en/v0.8.13/contracts.html#special-functions

Example:

contract Greeter {
    // ...

    receive() external payable {
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Petr Hejda