I want to programmatically mint a NFT on Sea Drop on OpenSea.
Here is a sample contract that I deployed to test out mint function Sepolia Etherscan
Here is the mint page OpenSea
If I switch to Write contract
tab on Etherscan to directly interact with the smart contract, I can see a mint function listed in ABI, which is called mintSeaDrop
, and it takes two arguments (minter
and quantity
)
With that function, I wrote a simple script to mint that NFT, but the result transaction always gets reverted!
const ethers = require("ethers");
const abi = [
{
inputs: [
{ internalType: "address", name: "minter", type: "address" },
{ internalType: "uint256", name: "quantity", type: "uint256" },
],
name: "mintSeaDrop",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];
const ca = "0x3be7fe2ebb70b38d2df12e83e31d8b859a6607a0";
const provider = new ethers.JsonRpcProvider("https://rpc-sepolia.rockx.com");
const wallet = new ethers.Wallet(privateKey, provider);
const contract = new ethers.Contract(ca, abi, wallet);
const minter = wallet.address;
const quantity = 1;
async function mintToken() {
try {
const tx = await contract.mintPublic(ca, minter, minter, quantity);
await tx.wait();
console.log("Minted token");
} catch (error) {
console.error("Error minting token", error);
}
}
mintToken();
After a while of researching, I found out that when I click mint on OpenSea, MetaMask asks me to confirm to mint the NFT, I switch to Hexdecimal tab to check out, the function that actually gets called is Mint Public
, takes 4 parameters (it is not listed in the ABI).
The function Mint Public
is in the file ISeaDrop.sol
according to Etherscan, but I don't know how to call it from the ABI since it is not listed here.
Is there any advice?