NFT's wont list on marketplace or add into the database

This is my cloud functions aswell.

cloud functions

Moralis.Cloud.define("getUserItems", async (request) => {

  const options = { address: request.params.token_address, chain: "ropsten" };

  const NFTowners = await Moralis.Web3API.token.getNFTOwners(options);

  const queryResults = NFTowners.result.filter(x => x.owner_of == request.user.attributes.accounts);

const results = [];

 for (let i = 0; i < queryResults.length; ++i) {

  results.push({

    "tokenObjectId": queryResults[i].id,

    "tokenid": queryResults[i].token_id,

    "tokenAddress": queryResults[i].token_address,

    "symbol": queryResults[i].symbol,

    "tokenUri": queryResults[i].token_uri,

  });

}

return results;

});

  Moralis.Cloud.define("getItems", async (request) => {

     

    const query = new Moralis.Query("ItemsForSale");

    query.notEqualTo("isSold", true);

    query.select("uid","askingPrice","tokenAddress","tokenId", "token.token_uri", "token.symbol","token.owner_of","token.id", "user.avatar","user.username");

 

    const queryResults = await query.find({useMasterKey:true});

    const results = [];

 

    for (let i = 0; i < queryResults.length; ++i) {

 

      if (!queryResults[i].attributes.token || !queryResults[i].attributes.user) continue;

 

      results.push({

        "uid": queryResults[i].attributes.uid,

        "tokenId": queryResults[i].attributes.tokenId,

        "tokenAddress": queryResults[i].attributes.tokenAddress,

        "askingPrice": queryResults[i].attributes.askingPrice,

 

        "symbol": queryResults[i].attributes.token.attributes.symbol,

        "tokenUri": queryResults[i].attributes.token.attributes.token_uri,

        "ownerOf": queryResults[i].attributes.token.attributes.owner_of,

        "tokenObjectId": queryResults[i].attributes.token.id,

       

        "sellerUsername": queryResults[i].attributes.user.attributes.username,

        "sellerAvatar": queryResults[i].attributes.user.attributes.avatar,

      });

    }

 

    return results;

  });

 

  Moralis.Cloud.beforeSave("ItemsForSale", async (request) => {

 

    const options = { address: "0xF276579917F17F5a157251C02d46993c1c7E2e42", chain: "ropsten" };

    const NFTowners = await Moralis.Web3API.token.getNFTOwners(options);

    const queryResults = NFTowners.result.filter(x => x.token_address == request.object.get('tokenAddress') && x.token_id == request.object.get('tokenId'));

    query.equalTo("token_address", request.object.get('tokenAddress'));

    query.equalTo("token_id", request.object.get('tokenId'));

    const object = queryResults[0];

    if (object){

      const owner = object.owner_of;

        const userQuery = new Moralis.Query(Moralis.User);

        userQuery.equalTo("accounts", owner);

        const userObject = await userQuery.first({useMasterKey:true});

        if (userObject){

            request.object.set('user', userObject);

        }

        request.object.set('token', object);

    }

  });

Moralis.Cloud.beforeSave("SoldItems", async (request) => {

 

    const query = new Moralis.Query("ItemsForSale");

    query.equalTo("uid", request.object.get('uid'));

    const item = await query.first();

    if (item){

      request.object.set('item', item);

      item.set('isSold', true);

      await item.save();

         

      const userQuery = new Moralis.Query(Moralis.User);

        userQuery.equalTo("accounts", request.object.get('buyer'));

      const userObject = await userQuery.first({useMasterKey:true});

      if (userObject){

          request.object.set('user', userObject);

      }

    }

  });

Hey Glad
I’ve been able to get a “from” address specified but now I’m getting a error involving the EVM. I also get a error on the third pop up of Metamask for not being able to estimate gas. I’m thinking the EVM issue might have something to do with the gas issue. I’m not completey sure.
Cheers

Screenshot gas issue for NFT marketplace

This error may occur when you are calling the function on the wrong chain or when you are trying to call a function which is private or internal.

Hi John
Is there anything else it could be?
I’m calling the function to the right chain and I’ve checked to see if there are any private or internals that I have to change to public or external but I’m continuing to get the same issue about the EVM.

What does the function do?

You can test it in remix to check if it is working.

The function is listing NFT’s to the marketplace and ok ill see if its the smart contract or not.
Cheers

My imports don’t work on remix but they work out of remix. Do you know a way to make them work in remix? I’m doing some trial and error now.
Cheers

Replace with this

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol";
1 Like

Ok Ill try that now.
Thank you

Hi John
everything works on remix fine and deploys. Ill keep doing some trouble shooting if you have no other suggestions.
I appreciate your help.
Cheers

I think it is a typo here. Function name should be addItemsToMarket

Is that the function which you are calling?

1 Like

Yes
That is the function I’m calling.
I’ve just changed it but I get the EVM error again now once that’s changed .

can you share the contract address, ABI, and function attributes? Maybe I can try from my side.

Ok Thank you John.
Marketplace contract address: 0xb94bb1b53ab68465cEB10b89E3B67Eae2Db003BA
Token Contract address: 0x99495223da7dFE1A14d5224Bc90bad4a01F0e58A
Function attributes:

1. description: "Description"
2. metadataFileHash: "QmWzvnPWAWKgUwU6RQF2ozGYfVC7LtT5KbqrWDvhF7xz6k"
3. metadataFilePath: "https://ipfs.moralis.io:2053/ipfs/QmWzvnPWAWKgUwU6RQF2ozGYfVC7LtT5KbqrWDvhF7xz6k"
4. name: "Name"
5. nftContractAddress: "0x99495223da7dFE1A14d5224Bc90bad4a01F0e58A"
6. nftFileHash: "QmSBhuJjpk89RSfVDYvQMhrRoMNUbQmgF6bUPFf8WvxK7a"
7. nftFilePath: "https://ipfs.moralis.io:2053/ipfs/QmSBhuJjpk89RSfVDYvQMhrRoMNUbQmgF6bUPFf8WvxK7a"

Abi

var tokenContractAbi = [

  {

    "inputs": [],

    "stateMutability": "nonpayable",

    "type": "constructor"

  },

  {

    "anonymous": false,

    "inputs": [

      {

        "indexed": true,

        "internalType": "address",

        "name": "owner",

        "type": "address"

      },

      {

        "indexed": true,

        "internalType": "address",

        "name": "approved",

        "type": "address"

      },

      {

        "indexed": true,

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      }

    ],

    "name": "Approval",

    "type": "event"

  },

  {

    "anonymous": false,

    "inputs": [

      {

        "indexed": true,

        "internalType": "address",

        "name": "owner",

        "type": "address"

      },

      {

        "indexed": true,

        "internalType": "address",

        "name": "operator",

        "type": "address"

      },

      {

        "indexed": false,

        "internalType": "bool",

        "name": "approved",

        "type": "bool"

      }

    ],

    "name": "ApprovalForAll",

    "type": "event"

  },

  {

    "anonymous": false,

    "inputs": [

      {

        "indexed": true,

        "internalType": "address",

        "name": "from",

        "type": "address"

      },

      {

        "indexed": true,

        "internalType": "address",

        "name": "to",

        "type": "address"

      },

      {

        "indexed": true,

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      }

    ],

    "name": "Transfer",

    "type": "event"

  },

  {

    "inputs": [

      {

        "internalType": "uint256",

        "name": "",

        "type": "uint256"

      }

    ],

    "name": "Items",

    "outputs": [

      {

        "internalType": "uint256",

        "name": "id",

        "type": "uint256"

      },

      {

        "internalType": "address",

        "name": "creator",

        "type": "address"

      },

      {

        "internalType": "string",

        "name": "uri",

        "type": "string"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [

      {

        "internalType": "address",

        "name": "to",

        "type": "address"

      },

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      }

    ],

    "name": "approve",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

  },

  {

    "inputs": [

      {

        "internalType": "address",

        "name": "owner",

        "type": "address"

      }

    ],

    "name": "balanceOf",

    "outputs": [

      {

        "internalType": "uint256",

        "name": "",

        "type": "uint256"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      }

    ],

    "name": "getApproved",

    "outputs": [

      {

        "internalType": "address",

        "name": "",

        "type": "address"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [

      {

        "internalType": "address",

        "name": "owner",

        "type": "address"

      },

      {

        "internalType": "address",

        "name": "operator",

        "type": "address"

      }

    ],

    "name": "isApprovedForAll",

    "outputs": [

      {

        "internalType": "bool",

        "name": "",

        "type": "bool"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [],

    "name": "name",

    "outputs": [

      {

        "internalType": "string",

        "name": "",

        "type": "string"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      }

    ],

    "name": "ownerOf",

    "outputs": [

      {

        "internalType": "address",

        "name": "",

        "type": "address"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [

      {

        "internalType": "address",

        "name": "from",

        "type": "address"

      },

      {

        "internalType": "address",

        "name": "to",

        "type": "address"

      },

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      }

    ],

    "name": "safeTransferFrom",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

  },

  {

    "inputs": [

      {

        "internalType": "address",

        "name": "from",

        "type": "address"

      },

      {

        "internalType": "address",

        "name": "to",

        "type": "address"

      },

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      },

      {

        "internalType": "bytes",

        "name": "_data",

        "type": "bytes"

      }

    ],

    "name": "safeTransferFrom",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

  },

  {

    "inputs": [

      {

        "internalType": "address",

        "name": "operator",

        "type": "address"

      },

      {

        "internalType": "bool",

        "name": "approved",

        "type": "bool"

      }

    ],

    "name": "setApprovalForAll",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

  },

  {

    "inputs": [

      {

        "internalType": "bytes4",

        "name": "interfaceId",

        "type": "bytes4"

      }

    ],

    "name": "supportsInterface",

    "outputs": [

      {

        "internalType": "bool",

        "name": "",

        "type": "bool"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [],

    "name": "symbol",

    "outputs": [

      {

        "internalType": "string",

        "name": "",

        "type": "string"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [

      {

        "internalType": "address",

        "name": "from",

        "type": "address"

      },

      {

        "internalType": "address",

        "name": "to",

        "type": "address"

      },

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      }

    ],

    "name": "transferFrom",

    "outputs": [],

    "stateMutability": "nonpayable",

    "type": "function"

  },

  {

    "inputs": [

      {

        "internalType": "string",

        "name": "uri",

        "type": "string"

      }

    ],

    "name": "createItem",

    "outputs": [

      {

        "internalType": "uint256",

        "name": "",

        "type": "uint256"

      }

    ],

    "stateMutability": "nonpayable",

    "type": "function"

  },

  {

    "inputs": [

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      }

    ],

    "name": "tokenURI",

    "outputs": [

      {

        "internalType": "string",

        "name": "",

        "type": "string"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  }

];

var marketplaceContractAbi = [

  {

    "anonymous": false,

    "inputs": [

      {

        "indexed": false,

        "internalType": "uint256",

        "name": "id",

        "type": "uint256"

      },

      {

        "indexed": false,

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      },

      {

        "indexed": false,

        "internalType": "address",

        "name": "tokenAddress",

        "type": "address"

      },

      {

        "indexed": false,

        "internalType": "uint256",

        "name": "askingPrice",

        "type": "uint256"

      }

    ],

    "name": "itemAdded",

    "type": "event"

  },

  {

    "anonymous": false,

    "inputs": [

      {

        "indexed": false,

        "internalType": "uint256",

        "name": "id",

        "type": "uint256"

      },

      {

        "indexed": false,

        "internalType": "address",

        "name": "buyer",

        "type": "address"

      },

      {

        "indexed": false,

        "internalType": "uint256",

        "name": "askingPrice",

        "type": "uint256"

      }

    ],

    "name": "itemSold",

    "type": "event"

  },

  {

    "inputs": [

      {

        "internalType": "uint256",

        "name": "",

        "type": "uint256"

      }

    ],

    "name": "itemsForSale",

    "outputs": [

      {

        "internalType": "uint256",

        "name": "id",

        "type": "uint256"

      },

      {

        "internalType": "address",

        "name": "tokenAddress",

        "type": "address"

      },

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      },

      {

        "internalType": "address payable",

        "name": "seller",

        "type": "address"

      },

      {

        "internalType": "uint256",

        "name": "askingPrice",

        "type": "uint256"

      },

      {

        "internalType": "bool",

        "name": "isSold",

        "type": "bool"

      }

    ],

    "stateMutability": "view",

    "type": "function",

    "constant": true

  },

  {

    "inputs": [

      {

        "internalType": "uint256",

        "name": "tokenId",

        "type": "uint256"

      },

      {

        "internalType": "address",

        "name": "tokenAddress",

        "type": "address"

      },

      {

        "internalType": "uint256",

        "name": "askingPrice",

        "type": "uint256"

      }

    ],

    "name": "addItemToMarket",

    "outputs": [

      {

        "internalType": "uint256",

        "name": "",

        "type": "uint256"

      }

    ],

    "stateMutability": "nonpayable",

    "type": "function"

  },

  {

    "inputs": [

      {

        "internalType": "uint256",

        "name": "id",

        "type": "uint256"

      }

    ],

    "name": "buyItem",

    "outputs": [],

    "stateMutability": "payable",

    "type": "function",

    "payable": true

  }

];

This is not a contract address
https://rinkeby.etherscan.io/address/0xb94bb1b53ab68465cEB10b89E3B67Eae2Db003BA

When i tried it gave me an error saying MetaMask - RPC Error: TxGasUtil - Trying to call a function on a non-contract address

This is how i am calling.

await marketplaceContract.methods.addItemToMarket(1, "0x99495223da7dFE1A14d5224Bc90bad4a01F0e58A", 1).send({ from: "AddYourWalletAddressHere" }, function (err, res) {
  if (err) {
    console.log("An error occurred", err)
    return
  }
  console.log("Result: ", res)
})
1 Like

I think you might of put the token contract address when calling instead of my marketplace contract.
My marketplace contract is 0xb94bb1b53ab68465cEB10b89E3B67Eae2Db003BA. Does this change the outcome when you call it?

oh wait, i think i checked on rinkeby chain

This function has OnlyItemOwner and HasTransferApproval modifiers. Do you meet these conditions? The error could be from these modifiers

Yes I do meet these conditions.
I have corrected the addItemsToMarket function to addItemToMarket.