Hey guys,
I am getting the following error when trying to deploy my NFT.sol contract (It is basically an ERC721 with some added features) to mumbai testnet. I am working with hardhat:
I have tried different gas settings on my hardhat config file, but it does not affect the performance. As you can see on the file below deploy-NFT.js I am using Infura, but I have also tried Alchemy, and it does not change anything. I am using transparent proxies but still getting the same error when I tried UUPS.
Yesterday I deployed this same contract to mumbai several times and it stopped working. When checking through mumbai polygonscan, there are some differences on the logs.
You can check it here:
Successful deployment: https://mumbai.polygonscan.com/tx/0x0ea17b19c5da5e36933a7eb7d2b6b946fb7a56de55ee0096e980ee02d7049482#eventlog
Failed deployment: https://mumbai.polygonscan.com/tx/0xd6342c46ad76b73436270c36a7793b5a2e25485793cfcaf5c800b4cb02cec9d5
Maybe the proxy contract is not being deployed properly?
Config file and script:
hardhat.config.js
require("@nomiclabs/hardhat-waffle");
require("@openzeppelin/hardhat-upgrades");
require("dotenv").config();
const privateKey = process.env.privateKey || "";
const infuraId = process.env.infuraKey || "";
const alchemyId = process.env.alchemyKey || "";
module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 1337,
},
development: {
url: "http://127.0.0.1:8545",
chainId: 1337, // Match any network id
gas: 500000000,
},
...(infuraId && {
mumbai_infura: {
url: `https://polygon-mumbai.infura.io/v3/${infuraId}`,
accounts: [privateKey],
gasLimit: 20000000,
gasPrice: 25000000000,
},
matic_infura: {
url: `https://polygon-mainnet.infura.io/v3/${infuraId}`,
accounts: [privateKey],
},
}),
...(alchemyId && {
mumbai_alchemy: {
url: `https://polygon-mumbai.g.alchemy.com/v2/${alchemyId}`,
accounts: [privateKey],
gasLimit: 20000000,
gasPrice: 25000000000,
},
matic_alchemy: {
url: `https://polygon-mainnet.g.alchemy.com/v2/${alchemyId}`,
accounts: [privateKey],
},
}),
},
solidity: {
version: "0.8.4",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
};
deployment script:
const { ethers, upgrades } = require("hardhat");
import { nftmarketaddress } from "../../../config";
import NFTData from "../../../artifacts/contracts/NFT.sol/NFT.json";
import MarketData from "../../../artifacts/contracts/Market.sol/NFTMarket.json";
import { getSecretConfig } from "../services/secret-manager";
async function getKeys() {
let config;
if (process.env.DEPLOY_SECRET_KEY) {
config = await getSecretConfig(process.env.DEPLOY_SECRET_KEY);
} else {
config = {
privateKey: process.env.privateKey ?? "",
alchemyKey: process.env.alchemyKey ?? "",
};
}
return config;
}
async function getSigner() {
const network = process.env.NETWORK || "";
let provider, kloovWallet, kloovAddress;
if (network) {
const keys = await getKeys();
provider = new ethers.providers.JsonRpcProvider(
`https://polygon-${network}.infura.io/v3/${keys.infuraKey}`
);
kloovWallet = new ethers.Wallet(keys.privateKey, provider);
kloovAddress = kloovWallet.address;
console.log(await provider.getFeeData());
} else {
provider = new ethers.providers.JsonRpcProvider();
kloovWallet = provider.getSigner();
kloovAddress = await kloovWallet.getAddress();
}
return { kloovWallet, kloovAddress };
}
export async function deployNFT(price, supply, url, artist) {
console.log(
"Deploying contract to: " +
(process.env.NETWORK ? process.env.NETWORK : "local ") +
" network"
);
process.env.DEBUG="*";
const { kloovWallet, kloovAddress } = await getSigner();
console.log("NFT contract being deployed from: " + kloovAddress);
const NFT = await ethers.getContractFactory("NFT", kloovWallet);
const nft = await upgrades.deployProxy(NFT, [nftmarketaddress, artist], {kind: "uups"});
await nft.deployed();
console.log("NFT deployed to:", nft.address);
/* next, create the token */
let contract = new ethers.Contract(nft.address, NFTData.abi, kloovWallet);
await contract.createToken(url, supply);
const priceValue = ethers.utils.parseUnits(price, "ether");
console.log("Token/s created");
/* then list the item for sale on the marketplace */
contract = new ethers.Contract(nftmarketaddress, MarketData.abi, kloovWallet);
const transaction = await contract.createMarketItem(
artist,
nft.address,
supply,
priceValue
);
const tx = await transaction.wait();
console.log("Item/s created");
const marketItemsCreated = tx.events[tx.events.length - 1];
return marketItemsCreated.args;
}
I would really appreciate your help, since this problem is difficulting the progress of the project.
Request any other file if you think is needed!
Thank you in advance.