Transaction reverted.. Invalid token id

After creating cancel-item.js in scripts:

I was running yarn hardhat run scripts/cancel-item.js --network localhost

and I got this error:

reason: "Error: VM Exception while processing transaction: reverted with reason string 'ERC721: invalid token ID'",
  code: 'UNPREDICTABLE_GAS_LIMIT',
  method: 'estimateGas',
  transaction: {
    from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    to: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
    data: '0xb2ddee06000000000000000000000000e7f1725e7734ce288f8367e1bb143e90bb3f05120000000000000000000000000000000000000000000000000000000000000001',
    accessList: null
  },
  error: ProviderError: Error: VM Exception while processing transaction: reverted with reason string 'ERC721: invalid token ID'
      at HttpProvider.request (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/hardhat/src/internal/core/providers/http.ts:78:19)
      at AutomaticSenderProvider.request (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/hardhat/src/internal/core/providers/accounts.ts:351:34)
      at AutomaticGasProvider.request (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:136:34)
      at AutomaticGasPriceProvider.request (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:153:36)
      at ChainIdValidatorProvider.request (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/hardhat/src/internal/core/providers/chainId.ts:66:34)
      at BackwardsCompatibilityProviderAdapter.send (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/hardhat/src/internal/core/providers/backwards-compatibility.ts:36:27)
      at EthersProviderWrapper.send (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:48)
      at EthersProviderWrapper.<anonymous> (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:601:31)
      at step (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
      at Object.next (/Users/zahratest/Desktop/hardhat-nft-marketplace/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)

not sure what you’re running in cancel-item script, but the error logs seems to say that the NFT w/ that token Id might not exist

Better you give more specifics on your code as well that’ll be much better!

Yes sure,

cancel-item.js

const { ethers, network } = require("hardhat");
const { moveBlocks } = require("../utils/move-blocks");

const TOKEN_ID = 1;

async function cancel() {
  const nftMarketplace = await ethers.getContract("NftMarketplace");
  const basicNft = await ethers.getContract("BasicNft");
  const tx = await nftMarketplace.cancelListing(basicNft.address, TOKEN_ID);
  await tx.wait(1);
  console.log("NFT Canceled!");
  if ((network.config.chainId = "31337")) {
    await moveBlocks(2, (sleepAmount = 1000));
  }
}

cancel()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

What does your cancelListing contract function look like? Check the tokenId of 1 you’re passing in, should it pass the conditions for that function to work?