My code is
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
pragma solidity >=0.8.17 <0.9.0;
contract bachi is ERC721, Ownable {
using strings for uint256;
uint256 public constant MAX_TOKENS = 999;
uint256 private constant TOKENS_RESERVED = 5;
uint256 public price = 9000000000000000;
uint256 public constant MAX_MINT_PER_TX = 2;
bool public isSaleActive;
uint256 public totalsupply;
mapping(address => uint256) private mintedperwallet;
string public baseuri;
string public baseExtension = ".json";
constructor() ERC721("bachi", "bac") {
// Base IPFS URI of the NFTS
baseuri = "ipfs://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/";
for (uint256 i = 1; i <= TOKENS_RESERVED; i) {
_safeMint(msg.sender, i);
}
totalsupply = TOKENS_RESERVED;
The problem is in using strings for uint256.
I have created the file name and the contract name same, but then also it is same error. Please give me a solution.
CodePudding user response:
It may be about you defined your pragme statement twice
CodePudding user response:
You have to remove one of two statement related to compiler version (pragma solidity
..). Then you have to include Strings.sol smart contract created for OpenZeppelin for using Strings smart contract.
I modified your original smart contract in this way:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract bachi is ERC721, Ownable {
using Strings for uint256;
uint256 public constant MAX_TOKENS = 999;
uint256 private constant TOKENS_RESERVED = 5;
uint256 public price = 9000000000000000;
uint256 public constant MAX_MINT_PER_TX = 2;
bool public isSaleActive;
uint256 public totalsupply;
mapping(address => uint256) private mintedperwallet;
string public baseuri;
string public baseExtension = ".json";
constructor() ERC721("bachi", "bac") {
// Base IPFS URI of the NFTS
baseuri = "ipfs://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/";
for (uint256 i = 1; i <= TOKENS_RESERVED; i) {
_safeMint(msg.sender, i);
}
totalsupply = TOKENS_RESERVED;
}
}