最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - MetaMask - RPC Error: Error: MetaMask Tx Signature: User denied transaction signature - Stack Overflow

programmeradmin0浏览0评论

In javascript I run contract's method

contract[methodName](...params, { from: myAccount }, (err, response) => {
    console.log('get transaction', methodName, err, response);
    if (err) return reject(err);
    resolve(response);
});

and then reject transaction through MetaMask. In console get an error

MetaMask - RPC Error: Error: MetaMask Tx Signature: User denied transaction signature.

But I can't catch this error in my code. Callback not working.

How can i catch this error in JS?

In javascript I run contract's method

contract[methodName](...params, { from: myAccount }, (err, response) => {
    console.log('get transaction', methodName, err, response);
    if (err) return reject(err);
    resolve(response);
});

and then reject transaction through MetaMask. In console get an error

MetaMask - RPC Error: Error: MetaMask Tx Signature: User denied transaction signature.

But I can't catch this error in my code. Callback not working.

How can i catch this error in JS?

Share Improve this question asked May 31, 2018 at 10:16 Угуйлук ДжагатамскиУгуйлук Джагатамски 1291 gold badge1 silver badge4 bronze badges 5
  • 1 Also having this problem currently.. – Noah Passalacqua Commented May 31, 2018 at 17:50
  • Same here. Doesn't work in Chrome (where I am running Metamask 4.7) but works in Firefox (running Metamask 3.x.x ) It pletely breaks control flow - not only the exception seems not to be thrown, but neither is executed code which follows the web3 call. – Patrik Stas Commented Jun 1, 2018 at 2:17
  • Same strange behavior, worked fine just few days ago. But now impossible to catch Metamask's exceptions... Looks like Chrome plugin problems. In Firefox still working well. – Anton Pegov Commented Jun 1, 2018 at 13:22
  • Jup, having the same issue in Chrome + Metamask + local testing environment. Would be nice to get a Metamask developer in here. – Yuri van Geffen Commented Jun 1, 2018 at 13:42
  • 1 Same, solutions? – imazzara Commented Jun 4, 2018 at 21:43
Add a ment  | 

2 Answers 2

Reset to default 2

Do this if you are using Ethers library:

contract.methodName(...params, { from: myAccount })
.then(tx => {
    //do whatever you want with tx
})
.catch(e => {
     if (e.code === 4001){
         //user rejected the transaction
     } 
});

I was also facing the same issue and I fixed it by using this library

https://github./enzoferey/ethers-error-parser

npm install @enzoferey/ethers-error-parser

import { getParsedEthersError } from "@enzoferey/ethers-error-parser";

try {
  const transaction = await someContract.someMethod();
  await transaction.wait();
} catch (error) {
  const parsedEthersError = getParsedEthersError(error);
  // parsedError.errorCode - contains a well defined error code (see full list below)
  // parsedError.context - contains a context based string providing additional information
  // profit ! 
}

If the user rejects the transaction then the error code will be REJECTED_TRANSACTION

You can find a plete list of error codes from official docs here: https://github./MetaMask/eth-rpc-errors/blob/main/src/error-constants.ts

发布评论

评论列表(0)

  1. 暂无评论