I'm super new in developing minting APIs. I am working on a react app for minting NFTs. I am using Hardhat/web3 & using a metamask wallet for testing. I'm just trying to build a basic minting UI & I am following a tutorial (https://www.youtube.com/watch?v=meTpMP0J5E8&t=803s). I managed to connect my wallet to the UI, but when I attempt to mint, I get these two errors, each of which is an error that I can't find a similar instance of anywhere online.

inpage.js:1 MetaMask - RPC Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"data":{"code":-32602,"message":"Trying to send a raw transaction with an invalid chainId. The expected chainId is 31337"}}}' {code: -32603, message: `[ethjs-query] while formatting outputs from RPC '{…valid chainId. The expected chainId is 31337"}}}'`}
Uncaught (in promise) {code: -32603, message: `[ethjs-query] while formatting outputs from RPC '{…valid chainId. The expected chainId is 31337"}}}'`, stack: '{\n  "code": -32603,\n  "message": "[ethjs-query] wh…gaeaoehlefnkodbefgpgknn/background-0.js:1:150045)'}

Any assistance or insight would be greatly appreciated :) Edit: Has no one ever come across this error before? I desperately need help, if anyone can help me please do

  • Can you please share some, especially how you load the "provider"
    – Adam Boudj
    Mar 18, 2022 at 16:13
  • That error usually means the function execution has failed. How did it fail? It depends on the contract, perhaps a require's condition failed, another error condition like calling an invalid address, accessing an array out of bound, etc.
    – Ismael
    Mar 20, 2022 at 17:30

1 Answer 1


By default, Metamask uses ChainId 1337, while Hardhat uses 31337. There are two ways to solve this.

In your Metamask extension settings, go in "Networks", change the ChainId to 31337.

Or, in your harhdat config, change your ChainId to 1337. See the Hardhat documentation about this issue: https://hardhat.org/metamask-issue.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.