简体   繁体   English

MetaMask - RPC 错误:执行恢复,简单的 NFT 迷你 Dapp

[英]MetaMask - RPC Error: execution reverted, Simple NFT Miniting Dapp

I'm building a simple NFT minting Dapp for fundraising.我正在构建一个简单的 NFT 铸造 Dapp 用于筹款。 I first deployed contracts on Polygon testnet and then on Ethereum testnet goerli.我首先在 Polygon 测试网上部署了合约,然后在以太坊测试网 goerli 上部署了合约。 While integrating在整合的同时在此处输入图像描述 , my front-end with my smart contracts using Ethers.js, I'm getting the same errors. ,我的智能合约前端使用 Ethers.js,我遇到了同样的错误。 Did my research and also tried some solutions available but still got the same errors.我进行了研究并尝试了一些可用的解决方案,但仍然遇到相同的错误。

Here is the full repo: https://github.com/DevABDee/WagmiPakistan You can use live-Server to run the application, I'm using simple HTML这是完整的仓库: https://github.com/DevABDee/WagmiPakistan您可以使用 live-Server 来运行应用程序,我使用的是简单HTML

My hardhat.config.js:我的 hardhat.config.js:

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config({ path: ".env" });

POLYGON_TESTNET_URL = process.env.POLYGON_TESTNET_URL;
GOERLI_TESTNET_URL = process.env.GOERLI_TESTNET_URL;
PRIVATE_KEY = process.env.PRIVATE_KEY;
ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;

module.exports = {
  solidity: {
    version: "0.8.7",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
  networks: {
    matic: {
      url: POLYGON_TESTNET_URL,
      accounts: [PRIVATE_KEY],
      gas: 2100000,
      gasPrice: 8000000000
    },
    goerli: {
      url: GOERLI_TESTNET_URL,
      accounts: [PRIVATE_KEY],
      gas: 2100000,
      gasPrice: 8000000000
    }
  },
  etherscan: {
    apiKey: ETHERSCAN_API_KEY
  }
};

Index.js:索引.js:

import { ethers } from "https://cdn-cors.ethers.io/lib/ethers-5.5.4.esm.min.js";
import {contractAddress, contractAbi} from  "./constants.js";

const mintBronze = document.getElementById('MintBronze');
const mintSteel = document.getElementById('MintSteel');
const mintGold = document.getElementById('MintGold');
const mintDiamond = document.getElementById('MintDiamond');
const mintPlatinum = document.getElementById('MintPlatinum');

mintBronze.onclick = MintBronze;
mintSteel.onclick = MintSteel;
mintGold.onclick = MintGold;
mintDiamond.onclick = MintDiamond;
mintPlatinum.onclick = MintPlatinum;

async function connect() {

    if (typeof window.ethereum !== 'undifined') {
        await window.ethereum.request({ method: "eth_requestAccounts" })
        console.log("Connected");
    } else {
        console.log("Get A Metamask Wallet");
    }

}

connect();

let provider = new ethers.providers.Web3Provider(window.ethereum)
let signer = provider.getSigner();
let wagmiPakistanContract = new ethers.Contract(contractAddress, contractAbi, signer)


async function MintBronze() {
    const mintBronze = wagmiPakistanContract.mintBronze();
    const Bronze = await mintBronze;
    console.log(`${Bronze} Minted`);
}
async function MintSteel() {
    const mintSteel = wagmiPakistanContract.mintSteel();
    const Steel = await mintSteel;
    console.log(`${Steel} Minted`);
}
async function MintGold() {
    const mintGold = wagmiPakistanContract.mintGold();
    const Gold = await mintGold;
    console.log(`${Gold} Minted`);
}
async function MintDiamond() {
    const mintDiamond = wagmiPakistanContract.mintDiamond();
    const Diamond = await mintDiamond;
    console.log(`${Diamond} Minted`);
}
async function MintPlatinum() {
    const mintPlatinum = wagmiPakistanContract.mintPlatinum();
    const Platinum = await mintPlatinum;
    console.log(`${Platinum} Minted`);
}

Pls help me out.请帮帮我。 Thanks谢谢

You are not sending any ether when calling the contract so the msg.value is 0. Here's how you would send ether when calling a function that requires a msg.value equal to 0.001 ether (As the function you defined in the smart contract requires the msg.value to be 0.001):调用合约时您没有发送任何以太币,因此msg.value为 0。以下是调用需要msg.value等于 0.001 以太币的 function 时发送以太币的方式(因为您在智能合约中定义的 function 需要msg.value为 0.001):

const mintBronze = wagmiPakistanContract.mintBronze({ value: ethers.utils.parseEther("0.001") });

Similarly for other functions, the syntax would be:与其他函数类似,语法为:

const mintSteel = wagmiPakistanContract.mintSteel({ value: ethers.utils.parseEther("0.002") });
const mintGold = wagmiPakistanContract.mintGold({ value: ethers.utils.parseEther("0.003") });
const mintDiamond = wagmiPakistanContract.mintDiamond({ value: ethers.utils.parseEther("0.004") });
const mintPlatinum = wagmiPakistanContract.mintPlatinum({ value: ethers.utils.parseEther("0.005") });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MetaMask - RPC 错误:执行恢复{代码:-32000,消息:'执行恢复'} - MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'} 如何将 metamask 连接到 dapp? - How to connect metamask to dapp? Metamask 发送 RPC 错误,尽管它在 Javascript 中被捕获 - Metamask sends RPC Error although it is caught in Javascript Metamask 返回 RPC 错误:错误:[ethjs-rpc] rpc 错误,有效载荷 {“id”:5715960965837,“jsonrpc”:“2.0”,“params”: - Metamask returns RPC Error: Error: [ethjs-rpc] rpc error with payload {“id”:5715960965837,“jsonrpc”:“2.0”,“params”: Web3.js 返回错误:执行已恢复 - Web3.js returned error: execution reverted MetaMask - RPC 错误:权限请求已挂起,在 Angular 10 - MetaMask - RPC Error: Permissions request already pending, in Angular 10 MetaMask - RPC 错误:错误:MetaMask Tx 签名:用户拒绝交易签名 - MetaMask - RPC Error: Error: MetaMask Tx Signature: User denied transaction signature MetaMask - RPC 错误:参数无效:必须提供以太坊地址 - MetaMask - RPC Error: Invalid parameters: must provide an Ethereum address 如何仅使用 dApp 限制 NFT 铸造 - How to restrict NFT minting using the dApp only 无法在 metamask 移动浏览器中加载 dapp - Cant load dapp in metamask mobile browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM