Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better handle of the revert raison of a call (issue #4454) #5962

Closed
wants to merge 7 commits into from
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,7 @@ Released with 1.0.0-beta.37 code base.
- Updated dependencies (#5885)

## [Unreleased]

### Fixed

- Fixed "Uncaught TypeError" calling a contract function that revert using MetaMask (#4454)
10 changes: 9 additions & 1 deletion packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,15 @@ Method.prototype.buildCall = function () {
if (!err && method.isRevertReasonString(result)){
reasonData = result.substring(10);
} else if (err && err.data){
reasonData = err.data.substring(10);
// workaround embedded error details got from some providers like MetaMask
if (typeof err.data === 'object') {
// Ganache has no `originalError` sub-object unlike others
var originalError = err.data.originalError ?? err.data;
reasonData = originalError.data.substring(10);
}
else {
reasonData = err.data.substring(10);
}
}

if (reasonData){
Expand Down