Rarible Clone: Metamask - RPC Error in ensureMarketplaceIsApproved function


I run the code as given here: https://github.com/MoralisWeb3/youtube-tutorials/tree/main/rarible-clone

I extended the functio where error occurs to:

ensureMarketplaceIsApproved = async (tokenId, tokenAddress) => {
    console.log("ensureMarketplaceIsApproved... tokenId=" + tokenId + " tokenAddress=" + tokenAddress);
    user = await Moralis.User.current();
    console.log("ensureMarketplaceIsApproved... user=", user);
    const userAddress = user.get('ethAddress');
    console.log("ensureMarketplaceIsApproved...     userAddress=" + userAddress);
    const contract = new web3.eth.Contract(tokenContractAbi, tokenAddress);
    console.log("ensureMarketplaceIsApproved...     contract=", contract);
    const approvedAddress = await contract.methods.getApproved(tokenId).call({from: userAddress});
    console.log("ensureMarketplaceIsApproved... approvedAddress=" + approvedAddress);
    console.log("ensureMarketplaceIsApproved... MPContr.Address=" + MARKETPLACE_CONTRACT_ADDRESS);
    if (approvedAddress != MARKETPLACE_CONTRACT_ADDRESS){
        await contract.methods.approve(MARKETPLACE_CONTRACT_ADDRESS,tokenId).send({from: userAddress});

After click on the “Put for sale”-button of a ‘My item’ item I get this error in the console:

renderUserItem... onclick user= ParseUser {id: "83APGEYVcl", _localId: undefined, _objCount: 0, className: "_User"}
main.js:340 ensureMarketplaceIsApproved... tokenId=2 tokenAddress=0xcfeb869f69431e42cdb54a4f4f105c19c080a601
main.js:342 ensureMarketplaceIsApproved... user= ParseUser {id: "83APGEYVcl", _localId: undefined, _objCount: 0, className: "_User"}
main.js:344 ensureMarketplaceIsApproved...     userAddress=0x95ced938f7991cd0dfcb48f0a06a40fa1af46ebc
main.js:346 ensureMarketplaceIsApproved...     contract= T {_requestManager: e, givenProvider: Proxy, providers: {…}, setProvider: ƒ, …}BatchRequest: ƒ ()clearSubscriptions: ƒ (e)currentProvider: (...)defaultAccount: (...)defaultBlock: (...)defaultChain: (...)defaultCommon: (...)defaultHardfork: (...)events: {Approval: ƒ, 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925: ƒ, Approval(address,address,uint256): ƒ, ApprovalForAll: ƒ, 0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31: ƒ, …}extend: ƒ (t)givenProvider: Proxy {_events: {…}, _eventsCount: 5, _maxListeners: 100, _log: a, isMetaMask: true, …}handleRevert: (...)methods: {Items: ƒ, 0x17b47cc4: ƒ, Items(uint256): ƒ, approve: ƒ, 0x095ea7b3: ƒ, …}options: {}providers: {WebsocketProvider: ƒ, HttpProvider: ƒ, IpcProvider: ƒ}setProvider: ƒ ()setRequestManager: ƒ (t)transactionBlockTimeout: (...)transactionConfirmationBlocks: (...)transactionPollingTimeout: (...)_address: "0xCfEB869F69431e42cdB54A4F4f105C19C080A601"_jsonInterface: (19) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]_provider: Proxy {_events: {…}, _eventsCount: 5, _maxListeners: 100, _log: a, isMetaMask: true, …}_requestManager: e {provider: Proxy, providers: {…}, subscriptions: Map(0)}get currentProvider: ƒ ()set currentProvider: ƒ (t)get defaultAccount: ƒ ()set defaultAccount: ƒ (e)get defaultBlock: ƒ ()set defaultBlock: ƒ (e)get defaultChain: ƒ ()set defaultChain: ƒ (e)get defaultCommon: ƒ ()set defaultCommon: ƒ (e)get defaultHardfork: ƒ ()set defaultHardfork: ƒ (e)get handleRevert: ƒ ()set handleRevert: ƒ (e)get transactionBlockTimeout: ƒ ()set transactionBlockTimeout: ƒ (e)get transactionConfirmationBlocks: ƒ ()set transactionConfirmationBlocks: ƒ (e)get transactionPollingTimeout: ƒ ()set transactionPollingTimeout: ƒ (e)__proto__: e
inpage.js:1 MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: "Internal JSON-RPC error.", data: {…}}code: -32603data: {message: "Reverting to invalid state checkpoint failed", code: -32000, data: {…}}message: "Internal JSON-RPC error."__proto__: Object
(anonymous) @ inpage.js:1
(anonymous) @ inpage.js:17
_runReturnHandlers @ inpage.js:17
_processRequest @ inpage.js:17
async function (async)
_processRequest @ inpage.js:17
_handle @ inpage.js:17
handle @ inpage.js:17
_rpcRequest @ inpage.js:1
(anonymous) @ inpage.js:1
request @ inpage.js:1
bound bound request @ util.js:693
c.send @ index.js:156
h @ index.js:615
n @ index.js:642
d._executeMethod @ index.js:769
ensureMarketplaceIsApproved @ main.js:347
async function (async)
ensureMarketplaceIsApproved @ main.js:341
userItem.getElementsByTagName.onclick @ main.js:293
async function (async)
userItem.getElementsByTagName.onclick @ main.js:287
index.js:50 Uncaught (in promise) Error: Internal JSON-RPC error.
  "message": "Reverting to invalid state checkpoint failed",
  "code": -32000,
  "data": {
    "stack": "Error: Reverting to invalid state checkpoint failed\n    at e.revert (C:\\Users\\micro\\AppData\\Roaming\\npm\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:55:643020)\n    at internal/util.js:297:30\n    at new Promise (<anonymous>)\n    at e.bound  (internal/util.js:296:12)\n    at t.<anonymous> (C:\\Users\\micro\\AppData\\Roaming\\npm\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:55:2011136)\n    at C:\\Users\\micro\\AppData\\Roaming\\npm\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:55:2007756\n    at Object.throw (C:\\Users\\micro\\AppData\\Roaming\\npm\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:55:2007861)\n    at o (C:\\Users\\micro\\AppData\\Roaming\\npm\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:55:2006626)",
    "name": "Error"
    at Object._fireError (index.js:50)
    at o (index.js:540)
    at a (util.js:689)
    at j (util.js:666)
    at b.run (browser.js:153)
    at p (browser.js:123)

I have ganache-cli -d running and moralis server is connected


I logged in to Metamask and it is using the Ganache-cli instance network (no error creating items)

Metamask -> Settings -> Advanced -> Reset account : did not solve it.

How to solve?

Seems I solved it all… functional the “rarible in 24hours” clone code works.

As local Eth blockchain i was using the ganache-cli , started from commandline as: ganache-cli -d
to keep eth addresses not renewed as i restarted the instance, but is buggy (Winows10 version).

Now i use the ganache GUI version (via port 7545) and code works completely, also the buy part.
(with Moralis server 0.0.224)

Great and thank you for the video’s as an example!

1 Like