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

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.

I tested again by deploying a new NFT contract and marketplace contract. The error is only happening from these modifiers.

modifier OnlyItemOwner(address tokenAddress, uint256 tokenId){
        IERC721 tokenContract = IERC721(tokenAddress);
        require(tokenContract.ownerOf(tokenId) == msg.sender);
        _;
    }
     modifier HasTransferApproval(address tokenAddress, uint256 tokenId) {
        IERC721 tokenContract = IERC721(tokenAddress);
        require(tokenContract.getApproved(tokenId) == address(this));
        _;
    }

Verify again if the modifier conditions are met.
getApproved(tokenId) should be equal to the marketplace contract and ownerOf(tokenId) should be equal to the wallet from which you are calling the function.

Ok Thank you
ill check them now