Transaction error not passed through #2328
Replies: 4 comments 6 replies
-
A lot of the error bubbling is handled by a bunch of regular expressions and string checking, because every node, network and backend seems to have their own custom formatting (this is something we are trying to address through the JSON-RPC standardizing meetings). Can you include a call that reliably reproduces this? Then I can figure out how to parse the response and return it. I will need to know the provider type, the URL you are connection to and a call address, data, etc. If you can produce a few lines on https://playground.ethers.org that demonstrates it, it will help me get around to it sooner. :) |
Beta Was this translation helpful? Give feedback.
-
The example below should work.
The problem is always the same. const ethers = require('ethers');
// CONFIGURATION
const url = "https://bsc-dataseed.binance.org/";
const privateKey = "ENTER PRIVATE KEY HERE";
const tokenInAddr = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; // WBNB
const tokenOutAaddr = "0xa3499dd7dbbbd93cb0f8303f8a8ace8d02508e73"; // LACE
const amountIn = "0.001"; // WBNB
const amountOut = "150000"; // LACE
const gasLimit = 200000;
const gasPrice = 5; // GWEI
var provider = ethers.getDefaultProvider(url);
var wallet = new ethers.Wallet(privateKey, provider);
var account = wallet.address;
const router = new ethers.Contract(
"0x10ED43C718714eb63d5aA57B78B54704E256024E", // PancakeSwap v2 ROUTER
[
'function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)'
],
wallet
);
const factory = new ethers.Contract(
"0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73", // PancakeSwap v2 FACTORY
['function getPair(address tokenA, address tokenB) external view returns (address pair)'],
wallet
);
let amountOutWei = ethers.utils.parseUnits(`${amountOut}`, 'ether');
let amountInWei = ethers.utils.parseUnits(`${amountIn}`, 'ether');
try {
const tx = await router.swapETHForExactTokens(
amountOutWei,
[tokenInAddr, tokenOutAaddr],
account,
Math.floor(Date.now()/1000) + (60 * 10),
{
'gasLimit': gasLimit,
'gasPrice': ethers.utils.parseUnits(`${gasPrice}`, 'gwei'),
'nonce' : null,
'value' : amountInWei
}
);
const receipt = await tx.wait();
console.log(receipt.transactionHash);
}
catch(e) {
console.log(e);
} |
Beta Was this translation helpful? Give feedback.
-
@zemse I modified my example from above and added your code (please check below).
const ethers = require('ethers');
// CONFIGURATION
const url = "https://bsc-dataseed.binance.org/";
const privateKey = "ENTER PRIVATE KEY HERE";
const tokenInAddr = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; // WBNB
const tokenOutAaddr = "0xa3499dd7dbbbd93cb0f8303f8a8ace8d02508e73"; // LACE
const amountIn = "0.001"; // WBNB
const amountOut = "150000"; // LACE
const gasLimit = 200000;
const gasPrice = 5; // GWEI
var provider = ethers.getDefaultProvider(url);
var wallet = new ethers.Wallet(privateKey, provider);
var account = wallet.address;
const router = new ethers.Contract(
"0x10ED43C718714eb63d5aA57B78B54704E256024E", // PancakeSwap v2 ROUTER
[
'function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)'
],
wallet
);
const factory = new ethers.Contract(
"0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73", // PancakeSwap v2 FACTORY
['function getPair(address tokenA, address tokenB) external view returns (address pair)'],
wallet
);
let amountOutWei = ethers.utils.parseUnits(`${amountOut}`, 'ether');
let amountInWei = ethers.utils.parseUnits(`${amountIn}`, 'ether');
try {
const tx = await router.swapETHForExactTokens(
amountOutWei,
[tokenInAddr, tokenOutAaddr],
account,
Math.floor(Date.now()/1000) + (60 * 10),
{
'gasLimit': gasLimit,
'gasPrice': ethers.utils.parseUnits(`${gasPrice}`, 'gwei'),
'nonce' : null,
'value' : amountInWei
}
);
const receipt = await tx.wait();
console.log(receipt.transactionHash);
}
catch(e) {
const returnData = await provider.call(e.receipt, e.receipt.blockNumber);
const iface = new ethers.utils.Interface(['function Error(string) public']);
const errorString = iface.decodeFunctionData('0x08c379a0', returnData);
console.log(errorString);
} |
Beta Was this translation helpful? Give feedback.
-
Any idea? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I'm not able to get the reason of a failed transaction from ethers.
I have a transaction that failed with reason "PancakeRouter: EXCESSIVE_INPUT_AMOUNT'.
Unfortunately this reason is not passed through by ethers.
I have to take the transaction hash and go to bscscan.com.
It is possible to receive the actual transaction failure with ethers?
transaction
Error: transaction failed (transactionHash="0x924f733ded871cb1a9f97cc0e209ff878e2a742b24f68ce5deecfd5b9a5f2569", transaction={"nonce":7,"gasPrice":{"type":"BigNumber","hex":"0x012a05f200"},"gasLimit":{"type":"BigNumber","hex":"0x030d40"},"to":"0x10ED43C718714eb63d5aA57B78B54704E256024E","value":{"type":"BigNumber","hex":"0x038d7ea4c68000"},"data":"0xfb3bdb41000000000000000000000000000000000000000000001fc3842bd1f071c000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000a010683a21d23ea043be0d283cc8f096a895e9e900000000000000000000000000000000000000000000000000000000619e1a7f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000a3499dd7dbbbd93cb0f8303f8a8ace8d02508e73","chainId":56,"v":148,"r":"0x8d9cffdb84f66aafa2637e70646ae60b363aee93cfc8cfa5ad5c792c217081e4","s":"0x43ffef1c32fc8d6c780160e6505550506b0cda5cbf014d4cc71a515e4103aba7","from":"0xa010683A21d23eA043bE0d283cc8f096A895e9E9","hash":"0x924f733ded871cb1a9f97cc0e209ff878e2a742b24f68ce5deecfd5b9a5f2569","type":null,"confirmations":0}, receipt={"to":"0x10ED43C718714eb63d5aA57B78B54704E256024E","from":"0xa010683A21d23eA043bE0d283cc8f096A895e9E9","contractAddress":null,"transactionIndex":267,"gasUsed":{"type":"BigNumber","hex":"0x7a82"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x17aeaf13d6f807964044af5c8113e5da1bbb53ad20b8f299c6eae1f00ae64e9d","transactionHash":"0x924f733ded871cb1a9f97cc0e209ff878e2a742b24f68ce5deecfd5b9a5f2569","logs":[],"blockNumber":12915439,"confirmations":1,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x02461690"},"status":0,"type":0,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.5.0) at Logger.makeError (/Volumes/GoogleDrive/Meine Ablage/Projekte/Coding/wolf/framework/node_modules/@ethersproject/logger/lib/index.js:199:21) at Logger.throwError (/Volumes/GoogleDrive/Meine Ablage/Projekte/Coding/wolf/framework/node_modules/@ethersproject/logger/lib/index.js:208:20) at WebSocketProvider.<anonymous> (/Volumes/GoogleDrive/Meine Ablage/Projekte/Coding/wolf/framework/node_modules/@ethersproject/providers/lib/base-provider.js:1471:36) at step (/Volumes/GoogleDrive/Meine Ablage/Projekte/Coding/wolf/framework/node_modules/@ethersproject/providers/lib/base-provider.js:48:23) at Object.next (/Volumes/GoogleDrive/Meine Ablage/Projekte/Coding/wolf/framework/node_modules/@ethersproject/providers/lib/base-provider.js:29:53) at fulfilled (/Volumes/GoogleDrive/Meine Ablage/Projekte/Coding/wolf/framework/node_modules/@ethersproject/providers/lib/base-provider.js:20:58) { reason: 'transaction failed', code: 'CALL_EXCEPTION', transactionHash: '0x924f733ded871cb1a9f97cc0e209ff878e2a742b24f68ce5deecfd5b9a5f2569', transaction: { nonce: 7, gasPrice: BigNumber { _hex: '0x012a05f200', _isBigNumber: true }, gasLimit: BigNumber { _hex: '0x030d40', _isBigNumber: true }, to: '0x10ED43C718714eb63d5aA57B78B54704E256024E', value: BigNumber { _hex: '0x038d7ea4c68000', _isBigNumber: true }, data: '0xfb3bdb41000000000000000000000000000000000000000000001fc3842bd1f071c000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000a010683a21d23ea043be0d283cc8f096a895e9e900000000000000000000000000000000000000000000000000000000619e1a7f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000a3499dd7dbbbd93cb0f8303f8a8ace8d02508e73', chainId: 56, v: 148, r: '0x8d9cffdb84f66aafa2637e70646ae60b363aee93cfc8cfa5ad5c792c217081e4', s: '0x43ffef1c32fc8d6c780160e6505550506b0cda5cbf014d4cc71a515e4103aba7', from: '0xa010683A21d23eA043bE0d283cc8f096A895e9E9', hash: '0x924f733ded871cb1a9f97cc0e209ff878e2a742b24f68ce5deecfd5b9a5f2569', type: null, confirmations: 0, wait: [Function (anonymous)] }, receipt: { to: '0x10ED43C718714eb63d5aA57B78B54704E256024E', from: '0xa010683A21d23eA043bE0d283cc8f096A895e9E9', contractAddress: null, transactionIndex: 267, gasUsed: BigNumber { _hex: '0x7a82', _isBigNumber: true }, logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', blockHash: '0x17aeaf13d6f807964044af5c8113e5da1bbb53ad20b8f299c6eae1f00ae64e9d', transactionHash: '0x924f733ded871cb1a9f97cc0e209ff878e2a742b24f68ce5deecfd5b9a5f2569', logs: [], blockNumber: 12915439, confirmations: 1, cumulativeGasUsed: BigNumber { _hex: '0x02461690', _isBigNumber: true }, status: 0, type: 0, byzantium: true } }
transaction
https://bscscan.com/tx/0x924f733ded871cb1a9f97cc0e209ff878e2a742b24f68ce5deecfd5b9a5f2569
Beta Was this translation helpful? Give feedback.
All reactions