I’m new to smart contracts and trying to set up NFT minting. I’m using Remix and the BSC network because they use 18 decimals like ETH.
I can do free minting and set a cost in BNB, but I want to use BUSD on BSC. I can check BUSD balances, but when I try to mint, I get this error:
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Returned error: {"jsonrpc":"2.0","error":"execution reverted","id":5075618818565261}
Here’s my test contract:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract CoolNFT is ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _itemCounter;
ERC20 public _paymentToken;
uint256 public _mintPrice = 1e18;
address tokenContract = 0xeB3Eb991D39Dac92616da64b7c6D5af5cCFf1627;
struct Item {
string seriesName;
}
mapping(uint256 => Item) private _items;
constructor(uint256 mintPrice) ERC721("CoolNFT", "COOL") {
_paymentToken = ERC20(tokenContract);
_mintPrice = mintPrice * 1e18;
}
function checkBalance() public view returns (uint256) {
return _paymentToken.balanceOf(msg.sender);
}
function createItem(address to, string memory tokenURI, string memory _seriesName)
public onlyOwner
returns (uint256)
{
require(_paymentToken.balanceOf(msg.sender) >= _mintPrice, "Not enough tokens");
_paymentToken.transferFrom(msg.sender, address(this), _mintPrice);
_itemCounter.increment();
uint256 newId = _itemCounter.current();
_mint(to, newId);
_items[newId].seriesName = _seriesName;
_setTokenURI(newId, tokenURI);
return newId;
}
function getSeriesName(uint256 tokenId) public view returns (string memory) {
return _items[tokenId].seriesName;
}
function updateMintPrice(uint256 newPrice) external onlyOwner {
_mintPrice = newPrice * 1e18;
}
}
What’s wrong with my code? How can I fix it?