I am getting the following Solidity error in my contract and I'm not sure what the problem is: Expected identifier but got '('
Here is my contract stripped down to the problem.
// SPDX-License-Identifier: MIT
// pragma solidity defines compiler version
pragma solidity ^0.8.10;
import '@openzeppelin/contracts/utils/Counters.sol';
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
contract NFTMarket is ReentrancyGuard {
using Counters for Counters.Counter;
Counters.Counter private _itemIds;
Counters.Counter private _itemsSold;
address payable owner;
uint256 listingPrice = 0.050 ether;
constructor() {
owner = payable(msg.sender);
}
function createMarketItem(
address nftContract, uint256 tokenId, uint256 price
) public payable nonReentrant {
_itemIds.increment();
uint256 itemId = _itemIds.current();
}
IERC721(nftContract).safeTransferFrom(msg.sender, address.this, tokenId);
^
Expected identifier but got '('
}
Does anybody have any idea how to resolve this properly?
Update: I didn't realize that I had it outside of the createMarketItem
function. That fixed that error. However, it now says member this not found
for address.this
. Shouldn't that work for the contract address?
// SPDX-License-Identifier: MIT
// pragma solidity defines compiler version
pragma solidity ^0.8.10;
import '@openzeppelin/contracts/utils/Counters.sol';
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
contract NFTMarket is ReentrancyGuard {
using Counters for Counters.Counter;
Counters.Counter private _itemIds;
Counters.Counter private _itemsSold;
address payable owner;
uint256 listingPrice = 0.050 ether;
constructor() {
owner = payable(msg.sender);
}
function createMarketItem(
address nftContract, uint256 tokenId, uint256 price
) public payable nonReentrant {
_itemIds.increment();
uint256 itemId = _itemIds.current();
IERC721(nftContract).safeTransferFrom(msg.sender, address.this, tokenId);
}
}