From e7b7c15198a9e8e48db93128fa1bf36945dba4d0 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Thu, 29 Oct 2020 08:59:16 +0800 Subject: [PATCH] feat: print program logs when transaction send fails (#13213) --- web3.js/src/connection.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index 9ffbce2a89..e881122194 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -2947,6 +2947,14 @@ export class Connection { const unsafeRes = await this._rpcRequest('sendTransaction', args); const res = SendTransactionRpcResult(unsafeRes); if (res.error) { + if (res.error.data) { + const logs = res.error.data.logs; + if (logs && Array.isArray(logs)) { + const traceIndent = '\n '; + const logTrace = traceIndent + logs.join(traceIndent); + console.error(res.error.message, logTrace); + } + } throw new Error('failed to send transaction: ' + res.error.message); } assert(typeof res.result !== 'undefined');