[英]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.