Deploying contract in remix

when i deploy this contract to the polygon network it automatically creates a new contract address that I do not have access to. This is supposed to a marketplace contract so obviously I need the keys. Is this a remix ide issue?
my prob

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;

import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

// import "hardhat/console.sol";

contract NFTMarket is ReentrancyGuard {
  using Counters for Counters.Counter;
  Counters.Counter private _itemIds;
  Counters.Counter private _itemsSold;

  address payable owner;
  uint256 listingPrice = 0.025 ether;

  constructor() {
    owner = payable(msg.sender);
  }

  struct MarketItem {
    uint itemId;
    address nftContract;
    uint256 tokenId;
    address payable seller;
    address payable owner;
    uint256 price;
    bool sold;
  }

  mapping(uint256 => MarketItem) private idToMarketItem;

  event MarketItemCreated (
    uint256 indexed itemId,
    address indexed nftContract,
    uint256 indexed tokenId,
    address seller,
    address owner,
    uint256 price,
    bool sold
  );

  /* Returns the listing price of the contract */
  function getListingPrice() public view returns (uint256) {
    return listingPrice;
  }
  
  /* Places an item for sale on the marketplace */
  function createMarketItem(
    address nftContract,
    uint256 tokenId,
    uint256 price
  ) public payable nonReentrant {
    require(price > 0, "Price must be at least 1 wei");
    require(msg.value == listingPrice, "Price must be equal to listing price");

    _itemIds.increment();
    uint256 itemId = _itemIds.current();
  
    idToMarketItem[itemId] =  MarketItem(
      itemId,
      nftContract,
      tokenId,
      payable(msg.sender),
      payable(address(0)),
      price,
      false
    );

    IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId);

    emit MarketItemCreated(
      itemId,
      nftContract,
      tokenId,
      msg.sender,
      address(0),
      price,
      false
    );
  }

  /* Creates the sale of a marketplace item */
  /* Transfers ownership of the item, as well as funds between parties */
  function createMarketSale(
    address nftContract,
    uint256 itemId
    ) public payable nonReentrant {
    uint price = idToMarketItem[itemId].price;
    uint tokenId = idToMarketItem[itemId].tokenId;
    require(msg.value == price, "Please submit the asking price in order to complete the purchase");

    idToMarketItem[itemId].seller.transfer(msg.value);
    IERC721(nftContract).transferFrom(address(this), msg.sender, tokenId);
    idToMarketItem[itemId].owner = payable(msg.sender);
    idToMarketItem[itemId].sold = true;
    _itemsSold.increment();
    payable(owner).transfer(listingPrice);
  }

  /* Returns all unsold market items */
  function fetchMarketItems() public view returns (MarketItem[] memory) {
    uint itemCount = _itemIds.current();
    uint unsoldItemCount = _itemIds.current() - _itemsSold.current();
    uint currentIndex = 0;

    MarketItem[] memory items = new MarketItem[](unsoldItemCount);
    for (uint i = 0; i < itemCount; i++) {
      if (idToMarketItem[i + 1].owner == address(0)) {
        uint currentId = i + 1;
        MarketItem storage currentItem = idToMarketItem[currentId];
        items[currentIndex] = currentItem;
        currentIndex += 1;
      }
    }
    return items;
  }

  /* Returns onlyl items that a user has purchased */
  function fetchMyNFTs() public view returns (MarketItem[] memory) {
    uint totalItemCount = _itemIds.current();
    uint itemCount = 0;
    uint currentIndex = 0;

    for (uint i = 0; i < totalItemCount; i++) {
      if (idToMarketItem[i + 1].owner == msg.sender) {
        itemCount += 1;
      }
    }

    MarketItem[] memory items = new MarketItem[](itemCount);
    for (uint i = 0; i < totalItemCount; i++) {
      if (idToMarketItem[i + 1].owner == msg.sender) {
        uint currentId = i + 1;
        MarketItem storage currentItem = idToMarketItem[currentId];
        items[currentIndex] = currentItem;
        currentIndex += 1;
      }
    }
    return items;
  }

  /* Returns only items a user has created */
  function fetchItemsCreated() public view returns (MarketItem[] memory) {
    uint totalItemCount = _itemIds.current();
    uint itemCount = 0;
    uint currentIndex = 0;

    for (uint i = 0; i < totalItemCount; i++) {
      if (idToMarketItem[i + 1].seller == msg.sender) {
        itemCount += 1;
      }
    }

    MarketItem[] memory items = new MarketItem[](itemCount);
    for (uint i = 0; i < totalItemCount; i++) {
      if (idToMarketItem[i + 1].seller == msg.sender) {
        uint currentId = i + 1;
        MarketItem storage currentItem = idToMarketItem[currentId];
        items[currentIndex] = currentItem;
        currentIndex += 1;
      }
    }
    return items;
  }
}


when a smart contract is created, you don’t have the keys to that smart contract, you can only call functions from that smart contract after that, and based on the code that the smart contract has, it can whitelist your address to make specific operations

Well my issue is im trying to make an event listener and its not getting anything from the address im deploying it from. the event listener works but the table isnt uploading. I figured it was because im not listening to the correct address

it looks like the first parameter for that topic should be uint256 instead of uint

here is the issue with that contract, im using the address that was given to me and from the constructor and it isnt allowing me to send any matic to it so i cant fund the transaction. im assuming that that is the contract i need to be watching instead of the addrss i used to deploy it correct?

If the contract was deployed ther by the constructor then thats the one that will emit the event im listing to right?

you deployed a new contract from the contractor of a contract? in that case you need to know the address of that new deployed contract, sometimes you can save the address of the deployed contract from constructor in the contract that did that deploy so what you can access it with a view function in case that you need that address

i found that contract on block explorer but I cant add any funds to it so it cant make a transaction you can view it here https://mumbai.polygonscan.com/address/0xEe2422eD2e49aACefaf70De6855055ECa1B2a3CD
you cant do anything with it and i dont see any functions. did it deploy correctly

the event sync is the only class thats working but even that only registered when i created it. It dosnt respond to the event

the original event sync doesn’t work also because the topic was not the right one, you can use the hash for the topic or use uint256 instead of uint

isnt the topic suposed to be the format of the function?
MarketItemCreated(uint, address, uint256, address, address, uint256, bool)
your saying i should use the transaction hash instead?

no the topic also has a hash that you can use it instead of that string that is not the right one now

when i make a new event the event sync updates with the new parameters but the class i create is empty and never updates when i call the function thats supposed to emit the event

event sync is the only change and it only occurs when i add a new event

or is it simply a server issue?

is there a way for me to get the private keys for the addres that the contract created? Im not able to send it anything the transactions always fail but this is the address that the contract was deployed to.


when I go to look at the contract details this is all i get

is it deployd correctly? why cant i send it any matic?

the contract may need to implement a payable function to be able to receive.

If that contract is deployed on matic/polygon then you can easily get the contract address and check for events, you will find in topic0 for the events the hash that should be put for topic

Solved
turns out you need this function to make it payable, heres the full docs
https://docs.soliditylang.org/en/v0.6.2/contracts.html#receive-ether-function

event Received(address, uint);
receive() external payable {
emit Received(msg.sender, msg.value);
}

2 Likes