Issue with NFT Minting Script
I have successfully deployed my smart contract and linked it to my Alchemy provider. However, when I try to run my minting script, I keep getting errors.
Here’s my minting script:
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 contractABI = require("../artifacts/contracts/TokenNFT.sol/TokenNFT.json");
const deployedAddress = "Contract_Address_Here";
const tokenContract = new web3Instance.eth.Contract(contractABI.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");
My environment variables:
ALCHEMY_URL = "https://eth-rinkeby.alchemyapi.io/v2/API_KEY"
WALLET_PRIVATE_KEY = "PRIVATE_KEY_HERE"
WALLET_ADDRESS = "PUBLIC_ADDRESS_HERE"
When I execute the script, I get some errors but I can’t figure out what’s causing them. Has anyone encountered similar issues with NFT minting scripts? What could be going wrong here?