I am newbie on solidity . trying to create NFT contract . I ve able to hardhat compile and deploy contract .
however during verify my contract with arguments and I am getting this error:
Error in plugin @nomiclabs/hardhat-etherscan: The contract verification failed. Reason: Fail - Unable to verify
I am also importing Open Zeppelin contracts ERC721Enumerable and Ownable.
Here's my contract.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract TigerNft is ERC721Enumerable, Ownable {
using SafeMath for uint256;
string public FTP_PROVENANCE = "";
uint256 public constant MAX_SUPPLY = 10000;
uint256 public constant MAX_PUBLIC_MINT = 2;
uint256 public constant MINT_PRICE = 28000000000000000; //0.028 ether;
string private _baseTokenURI;
uint256 public startingIndexBlock;
uint256 public startingIndex;
uint256 public REVEAL_TIMESTAMP;
bool public saleIsActive = false;
bool public isAllowListActive = false;
mapping(address => uint256) public _allowList;
constructor() ERC721("FortuneTigersPunk", "FTP") {
_baseTokenURI = "ipfs://QmNm3JHSGhBgL5D5sBov2kjAtxDKEoC9SF1Rq81Tqt52jp/";
}
modifier callerIsUser() {
require(tx.origin == msg.sender, "Caller is contract");
_;
}
/* Set provenance once it's calculated
This function is to update the hash of the image containing all the apes. This image is generated and stored outside of the blockchain */
function setProvenanceHash(string memory provenanceHash) public onlyOwner
{
FTP_PROVENANCE = provenanceHash;
}
function setBaseURI(string memory baseURI) public onlyOwner {
setBaseURI(baseURI);
}
function setIsAllowListActive(bool _isAllowListActive) external onlyOwner {
isAllowListActive = _isAllowListActive;
}
function setAllowList(address[] calldata addresses, uint8 numAllowedToMint) external onlyOwner {
for (uint256 i = 0; i < addresses.length; i ) {
_allowList[addresses[i]] = numAllowedToMint;
}
}
function numAvailableToMint(address addr) external view returns (uint256) {
return _allowList[addr];
}
function mintAllowList(uint8 numberOfTokens) external payable{
uint256 ts = totalSupply();
require(isAllowListActive, "Allow list is not active");
require(numberOfTokens <= _allowList[msg.sender], "Exceeded max available to purchase");
require(ts numberOfTokens <= MAX_SUPPLY, "Purchase would exceed max tokens");
require(MINT_PRICE.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
_allowList[msg.sender] -= numberOfTokens;
for (uint256 i = 0; i < numberOfTokens; i ) {
_safeMint(msg.sender, ts i);
}
}
function setSaleState() public onlyOwner {
saleIsActive = !saleIsActive;
}
function mint(uint numberOfTokens) public payable {
uint256 ts = totalSupply();
require(saleIsActive, "Sale must be active to mint tokens");
require(numberOfTokens <= MAX_PUBLIC_MINT, "Exceeded max token purchase");
require(ts numberOfTokens <= MAX_SUPPLY, "Purchase would exceed max tokens");
require(MINT_PRICE.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
for (uint i = 0; i < numberOfTokens; i ) {
if (totalSupply() < MAX_SUPPLY) {
_safeMint(msg.sender, ts i);
}
}
// If we haven't set the starting index and this is either 1) the last saleable token or 2) the first token to be sold after
// the end of pre-sale, set the starting index block
if (startingIndexBlock == 0 && (totalSupply() == MAX_SUPPLY || block.timestamp >= REVEAL_TIMESTAMP)) {
startingIndexBlock = block.number;
}
}
function withdraw() public onlyOwner {
uint balance = address(this).balance;
payable(msg.sender).transfer(balance);
}
}
Here's my deploy.ts
import { ethers} from "hardhat"
const main = async () =>{
const FTPFactory = await ethers.getContractFactory("TigerNft") ;
const FTPContract = await FTPFactory.deploy();
console.log(`NFT address: ${FTPContract.address}`);
}
main().catch((error)=> {
console.error(error);
process.exitCode =1;
});
Here's my hardhat.config.ts
import * as dotenv from "dotenv";
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@nomiclabs/hardhat-ethers";
import "@typechain/hardhat";
import "hardhat-gas-reporter";
dotenv.config();
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
const config: HardhatUserConfig = {
solidity: "0.8.4",
networks: {
rinkeby: {
url: process.env.RINKEBY_URL,
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
currency: "USD",
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
};
export default config;
CodePudding user response:
I fixed this error
try to put const FTPContract = await FTPFactory.deploy("FortuneTigersPunk", "FTP");
compile, deploy again and verify.
CodePudding user response:
i try import factories from typechain and its working fine now.
However i still dont know it it failed at 1st stage without import factories.
import { ethers} from "hardhat"
import { TigerNft__factory} from "../typechain-types";
const main = async () =>{
// const FTPFactory = await ethers.getContractFactory("TigerNft") ;
const FTPFactory = await ethers.getContractFactory("TigerNft") as TigerNft__factory;
const FTPContract = await FTPFactory.deploy();
// const FTPContract = await FTPFactory.deploy("FortuneTigersPunk", "FTP");
// const MAXNFT = (await ethers.getContractFactory("MaxNFT")) as MaxNFT__factory;
//const nft = await MAXNFT.deploy();
// console.log(`NFT address: ${nft.address}`);
console.log(`NFT address: ${FTPContract.address}`);
}
main().catch((error)=> {
console.error(error);
process.exitCode =1;
});