My Setup
I have successfully deployed my smart contract and linked it with my Alchemy provider. Everything seems to be configured properly but I’m running into issues when executing the minting process.
Code Files
create-nft.js
require('dotenv').config();
const ALCHEMY_URL = process.env.ALCHEMY_URL;
const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
const WALLET_PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY;
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
const web3Instance = createAlchemyWeb3(ALCHEMY_URL);
const nftArtifact = require("../artifacts/contracts/TokenNFT.sol/TokenNFT.json");
const deployedAddress = "Contract_Address_Here";
const tokenContract = new web3Instance.eth.Contract(nftArtifact.abi, deployedAddress);
async function createNFT(metadataURI) {
const txCount = await web3Instance.eth.getTransactionCount(WALLET_ADDRESS, 'latest');
const transaction = {
'from': WALLET_ADDRESS,
'to': deployedAddress,
'nonce': txCount,
'gas': 500000,
'data': tokenContract.methods.createNFT(WALLET_ADDRESS, metadataURI).encodeABI()
};
const signedTransaction = web3Instance.eth.accounts.signTransaction(transaction, WALLET_PRIVATE_KEY);
signedTransaction.then((result) => {
web3Instance.eth.sendSignedTransaction(result.rawTransaction, function(error, txHash) {
if (!error) {
console.log("Transaction hash: ", txHash, "\nCheck your transaction status on Alchemy!");
} else {
console.log("Error occurred:", error)
}
});
}).catch((error) => {
console.log("Transaction failed:", error);
});
}
createNFT("https://gateway.pinata.cloud/ipfs/My_Metadata_Hash");
Environment variables (.env)
ALCHEMY_URL = "https://eth-rinkeby.alchemyapi.io/v2/YOUR_KEY"
WALLET_PRIVATE_KEY = "YOUR_PRIVATE_KEY"
WALLET_ADDRESS = "YOUR_WALLET_ADDRESS"
The Problem
When I run the minting script, I encounter errors in the terminal. The contract deployment worked fine, but the actual NFT creation process fails. Has anyone experienced similar issues with NFT minting? What could be causing these errors during execution?