当合同被部署在Polygon(孟买/Mainnet)上时,如何接受Weth的付款?

发布于 2025-01-28 17:38:47 字数 1898 浏览 2 评论 0 原文

我正在建立一个琐事游戏支付系统,用户可以支付价值5美元的ETH来玩。 以下是合同的一部分,也是我认为我遇到麻烦的地区

// 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");


  }

}

部署脚本

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

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

  await deployer.deploy(Trivia, WETHContractMumbaiTestnet);
}

我能够将合同编译并成功部署在孟买测试网上。

但是,当我尝试与 Remix ide内的合同进行互动(连接到MetAmask并切换到孟买TestNet之后),以便为了付费进行播放,我会收到以下错误:

气体估计错误。我不知道我在做什么错。我确保我的钱包里有足够的韦斯。 我什至更改为另一个令牌(链接),并试图用链接令牌付款,但它行不通。

请专业人士告诉我,请在这里做错了什么。我已经停留了几天了。

友好,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

匿名的好友 2025-02-04 17:38:47

您是否批准了令牌转移,在 weth 合同上拨打批准方法?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文