I am having the following contract:
pragma solidity >=0.7.0 <0.9.0;
import "./IERC165.sol";
import "./IERC721.sol";
import "./IERC721Enumerable.sol";
import "./ERC165.sol";
import "./Strings.sol";
import "./Address.sol";
import "./IERC721Metadata.sol";
import "./IERC721Receiver.sol";
import "./ERC721.sol";
import "./ERC721Enumerable.sol";
import "./Ownable.sol";
contract rNFT is ERC721Enumerable, Ownable {
using Strings for uint256;
string baseURI; //NFT json is saved
string linkURL;
string public baseExtension = ".json";
uint256 public cost; // = 0.0 ether;
uint256 public maxMintAmount = 1;
bool public isInVault = false;
event Logging(string value);
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
// public
function mint(string memory _linkURL) public payable returns (uint) {
uint256 supply = totalSupply();
uint256 tokenID = supply + 1;
if (msg.sender != owner()) {
require(msg.value >= cost);
}
emit Logging(_linkURL);
setLinkURL(_linkURL);
_safeMint(msg.sender, tokenID);
return tokenID;
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
//only owner
function setIsInVault() public onlyOwner {
isInVault = true;
}
function setLinkURL(string memory _linkUrl) public onlyOwner {
linkURL = _linkUrl;
}
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
function withdraw() public payable onlyOwner {
// Do not remove this otherwise you will not be able to withdraw the funds.
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
}
}
All above imports are contracts from openzeppelin.
When calling the mint
function with parameters I get in ganache:
[9:49:22 PM] eth_getTransactionCount[9:49:24 PM] eth_blockNumber[9:49:37 PM] eth_sendRawTransaction[9:49:39 PM] Transaction: 0xcf9c12e58bf28a20a91bce248f1568263f4744bc31f7220f39e3add21a93ce4b[9:49:41 PM] Gas usage: 28684[9:49:41 PM] Block Number: 10[9:49:41 PM] Block Time: Wed May 25 2022 21:49:39 GMT+0200 (Central European Summer Time)[9:49:41 PM] Runtime Error: revert[9:49:41 PM] Revert reason: Ownable: caller is not the owner
I am having:
npm --version = 8.5.5
node --version = v16.15.0
truffle --version = Truffle v5.5.5 - a development framework for Ethereum
Ubuntu 20.04.4 LTS
My mint()
is public and can be called from everyone.
Any suggestions what I am doing wrong?