How To Accept Payment In WETH When The Contract Is Deployed on Polygon (Mumbai/Mainnet)?

367 Views Asked by At

I am building a trivia game payment system, where users can pay $5 worth of ETH to play. Below is a piece of the contract and the area where I think I am having trouble

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract Trivia is Ownable {

  IERC20 public WETHContract;
  uint256 playingFee = 440000000000000; // 0.00044 ether; // ~ $5 USD / 440000 GWei / 440000000000000 Wei
  
  constructor(IERC20 _LinkContract) public payable {
      WETHContract = _WETHContract;
  }

  receive() external payable {
      // what to do when receiving funds...
  }

  function payToPlay() public payable {
      require(WETHContract.transferFrom(
            msg.sender,
            address(this),
            playingFee 
        ),
        "You do not have enough WETH To Pay"
      );

      // (bool sent, ) = payable(address(this)).call{value: playingFee}("");
      // require(sent, "Failed to send fee");


  }

}

Deployment Script

const Trivia = artifacts.require("Trivia");
const WETHContractMumbaiTestnet = "0xa6fa4fb5f76172d178d61b04b0ecd319c5d1c0aa"

module.exports = async (deployer, networks, accounts) => {

  await deployer.deploy(Trivia, WETHContractMumbaiTestnet);
}

I am able to compile the contract and deploy it successfully on the Mumbai testnet.

But When I try to interact with the contract inside the Remix IDE (After connecting to Metamask and Switching to the Mumbai testnet), in order to pay to play, I get the following error:

enter image description here

A Gas estimate error. I don't know what I am doing wrong. I made sure I had enough WETH in my wallet. I even changed to another token (LINK) and tried to pay with the LINK token, but it did not work.

Can a professional tell me what I am doing wrong here, please. I have been stuck with this for days now.

Amicably,

1

There are 1 best solutions below

1
On

Did you approve the token transfer, calling the approve method on the WEth contract?