Solidity

MetaMask - RPC 錯誤:執行恢復,簡單的 NFT 迷你 Dapp

  • September 11, 2022

我正在建構一個簡單的 NFT 鑄造 Dapp 用於籌款。我首先在 Polygon 測試網上部署了合約,然後在乙太坊測試網 goerli 上部署了合約。在在此處輸入圖像描述使用 Ethers.js 將我的前端與我的智能合約集成時,我遇到了同樣的錯誤。我進行了研究並嘗試了一些可用的解決方案,但仍然遇到相同的錯誤。

這是完整的倉庫:https ://github.com/DevABDee/WagmiPakistan 您可以使用 live-Server 來執行應用程序,我使用的是簡單的HTML

我的 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
 }
};

索引.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`);
}

請幫幫我。謝謝

您想檢查您部署到測試網的合約地址是否正確。如果是,請檢查您呼叫的方法是否正確。最後,檢查函式呼叫中的參數是否正確。

引用自:https://ethereum.stackexchange.com/questions/135398