I’m trying to build an NFT site… following a video on Youtube I got to the part where I need to deploy my contract.
When I try to run npx hardhat run scripts/deploy.js --network goerli
this message comes normally:
Lock with 0.001ETH and unlock timestamp 1682374138 deployed to 0x0284782356e7886a9Be78b57DA90e69167cB6CE2″
But when I try to see the contract in https://goerli.etherscan.io/address/0x0284782356e7886a9Be78b57DA90e69167cB6CE2 it shows that I do not have any contract.
The only thing I did differently from the youtube video adds the gasPrice
on hardhat.config.js, cause without that I got another error saying that I don’t have founds (I have 0.0858 goerli eth). Can someone help me?
Deploy.js:
const hre = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
console.log("Account balance:", (await deployer.getBalance()).toString());
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
const unlockTime = currentTimestampInSeconds + 60;
const lockedAmount = hre.ethers.utils.parseEther("0.001");
const ethAmount = ethers.utils.parseEther('0.01');
const Lock = await hre.ethers.getContractFactory("Lock");
const lock = await Lock.deploy();
console.log(
`Lock with ${ethers.utils.formatEther(lockedAmount)}ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`
);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
const dotenv = require("dotenv");
require('dotenv').config();
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.18",
networks: {
goerli: {
url: process.env.REACT_APP_GOERLI_RPC_URL,
accounts: [process.env.REACT_APP_PRIVATE_KEY],
gasPrice: 500000
},
},
etherscan:{
apiKey: process.env.REACT_APP_ETHERSCAN_KEY
}
};
.env:
REACT_APP_GOERLI_RPC_URL='' //my url to infura api key
REACT_APP_ETHERSCAN_KEY='' //my etherscan key
REACT_APP_PRIVATE_KEY='' //my private key
Lock.sol (contract):
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
contract Lock is ERC721, Ownable{
uint256 public mintPrice;
uint256 public totalSupply;
uint256 public maxSupply;
uint256 public maxPerWallet;
bool public isPublicMintEnabled;
string internal baseTokenUri;
address payable public withdrawWallet;
mapping(address => uint256) public walletMints;
constructor() payable ERC721('Lock', 'GB'){
mintPrice = 0.00000001 ether;
totalSupply = 0;
maxSupply = 1000;
maxPerWallet = 3;
}
function setIsPublicMintEnabled(bool isPublicMintEnabled_) external onlyOwner{
isPublicMintEnabled = isPublicMintEnabled_;
}
function setBaseTokenUri(string calldata baseTokenUri_) external onlyOwner {
baseTokenUri = baseTokenUri_;
}
function tokenURI(uint256 tokenId_) public view override returns (string memory){
require(_exists(tokenId_),'Token does not exists');
return string(abi.encodePacked(baseTokenUri, Strings.toString(tokenId_),".json"));
}
function withdraw() external onlyOwner {
(bool success, ) = withdrawWallet.call{value: address(this).balance}('');
require(success, 'withdraw failed');
}
function mint(uint256 quantity_) public payable {
require(isPublicMintEnabled, 'minting not enabled');
require(msg.value == quantity_ * mintPrice, 'wrong mint value');
require(totalSupply + quantity_ <= maxSupply, 'sold out');
require(walletMints[msg.sender] + quantity_ <= maxPerWallet, 'exceed max wallet');
for(uint256 i=0; i<quantity_; i++){
uint256 newTokenId = totalSupply + 1;
totalSupply ++;
_safeMint(msg.sender, newTokenId);
}
}
}