Estoy tratando de crear mi propia fábrica de contratos NFT, pero falla en la red principal. Tengo ETH en mi billetera. En prueba funciona bien. Aquí está mi contrato:
//Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721) // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; contract NFT is ERC721URIStorage, Ownable { using Counters for Counters.Counter; Counters.Counter private _tokenIds; constructor() ERC721("NFT", "NFT") {} function mintNFT(address recipient, string memory tokenURI) public onlyOwner returns (uint256) { _tokenIds.increment(); uint256 newItemId = _tokenIds.current(); _mint(recipient, newItemId); _setTokenURI(newItemId, tokenURI); return newItemId; } }Aquí está mi secuencia de comandos de implementación de contrato
const MyNFT = await ethers.getContractFactory("NFT"); const gasPrice = await MyNFT.signer.getGasPrice(); const estimatedGas2 = await ethers.provider.estimateGas(MyNFT.getDeployTransaction().data) const estGas = await MyNFT.signer.estimateGas({ maxFeePerGas: gasPrice + 1, gasLimit: estimatedGas2, maxPriorityFeePerGas: gasPrice + 1, value: 0 }); console.log(estGas); console.log (gasPrice * estimatedGas2); console.log(await MyNFT.signer.getBalance()); const myNFT = await MyNFT.deploy(); await myNFT.deployed();los resultados en el registro de la consola son:
BigNumber { value: "53000" } 5060147051722000 BigNumber { value: "83341883765736405" }y error
Error: fondos insuficientes para el costo de transacción intrínseco [Consulte: https://links.ethers.org/v5-errors-INSUFFICIENT_FUNDS] (error={"name":"ProviderError","code":-32000,"_isProviderError": verdadero}, método="enviarTransacción", transacción=indefinido, código=FONDOS_INSUFICIENTES, versión=proveedores/5.6.2)
¿Cómo puede ser fondos insuficientes? 83341883765736405 es más de 5060147051722000
Subestimas el precio del gas. 53000 es demasiado bajo. Debe ser alrededor de 2774584 en la red principal para su contrato. Pruebe algo como esto en su secuencia de comandos de implementación:
const MyNFT = await ethers.getContractFactory('NFT'); const gasPrice = await MyNFT.signer.getGasPrice(); console.log(`Current gas price: ${gasPrice}`); const estimatedGas = await MyNFT.signer.estimateGas( MyNFT.getDeployTransaction(), ); console.log(`Estimated gas: ${estimatedGas}`); const deploymentPrice = gasPrice.mul(estimatedGas); const deployerBalance = await MyNFT.signer.getBalance(); console.log(`Deployer balance: ${ethers.utils.formatEther(deployerBalance)}`); console.log(`Deployment price: ${ethers.utils.formatEther(deploymentPrice)}`); if (deployerBalance.lt(deploymentPrice)) { throw new Error( `Insufficient funds. Top up your account balance by ${ethers.utils.formatEther( deploymentPrice.sub(deployerBalance), )}`, ); } const myNFT = await MyNFT.deploy(); await myNFT.deployed();y la salida es:
Current gas price: 20850635414 Estimated gas: 2774584 Deployer balance: your-balance Deployment price: 0.057851839409517776 An unexpected error occurred: Error: Insufficient funds. Top up your account balance by ???