use ethers to decode revert reason

pull/7/head
yann300 7 years ago
parent c0297d9d4c
commit 3d214db19f
  1. 5
      remix-lib/src/execution/txExecution.js

@ -1,5 +1,5 @@
'use strict'
var ethJSABI = require('ethereumjs-abi')
var ethers = require('ethers')
module.exports = {
/**
@ -86,7 +86,8 @@ module.exports = {
var returnData = txResult.result.vm.return
// It is the hash of Error(string)
if (returnData && (returnData.slice(0, 4).toString('hex') === '08c379a0')) {
var reason = ethJSABI.rawDecode(['string'], returnData.slice(4))[0]
var abiCoder = new ethers.utils.AbiCoder()
var reason = abiCoder.decode(['string'], returnData.slice(4))[0]
msg = `\tThe transaction has been reverted to the initial state.\nReason provided by the contract: "${reason}".`
} else {
msg = `\tThe transaction has been reverted to the initial state.\nNote: The constructor should be payable if you send value.`

Loading…
Cancel
Save