The code below gives me the exceeds allowance or always failing transaction error but when i check my contract on remix i can see that the transaction goes through, makes the correct state changes and works as expected. In The assignment executionMetrics becomes undefined. I've been sitting trying to figure out the problem for 4hrs and I'm completely stuck. Anyone knows what's going on?

async function someAsyncFunc(){
  bookingPromiseArr = []
  let promise = instance.methods.bookTrip(tripKey).send({
    from: accounts[0],
    gasPrice: GAS_PRICE,
    value: 1,})
  let executionMetrics = await executePromises(bookingPromiseArr, txStartTime)

async function executePromises(promisesArr, txStartTime) {
  await Promise.all(promisesArr)
    .then((receipts) => {
      let totalGasUsed = 0
      let txElapsedTime = Date.now() - txStartTime
      let lastBlock = receipts[receipts.length - 1].blockNumber
      receipts.forEach((receipt) => {
        totalGasUsed += receipt.gasUsed
        lastBlock =
          receipt.blockNumber > lastBlock ? receipt.blockNumber : lastBlock
      // I've console logged here and seen that I've reached this point
      return {
        txElapsedTime: txElapsedTime,
        totalGasUsed: totalGasUsed,
        lastBlock: lastBlock,
    .catch((error) => {
      console.log('multipleTX():', error)

The smart contract function invoked:

function bookTrip(uint256 key) external payable requireTrip(key) nonBookedPassenger(key){
        Trip storage trip = trips[key];
        trip.passengers[msg.sender] = trip.price;
        emit LogNewTripPassenger(msg.sender, key, trip.price);

Error log:

(node:23524) UnhandledPromiseRejectionWarning: Error: gas required exceeds allowance (8000029
) or always failing transaction
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules\@truffle\hdw
    at XMLHttpRequest.request.onreadystatechange (C:\Users\Diddi\Documents\mjukvaruteknik\exa
    at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Diddi\Documents\mjukvaruteknik\exame
    at XMLHttpRequest._setReadyState (C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\t
    at XMLHttpRequest._onHttpResponseEnd (C:\Users\Diddi\Documents\mjukvaruteknik\examensarbe
    at IncomingMessage.<anonymous> (C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqd
    at IncomingMessage.emit (events.js:228:7)
    at endReadableNT (_stream_readable.js:1185:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
(node:23524) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error origin
ated either by throwing inside of an async function without a catch block, or by rejecting a
promise which was not handled with .catch(). (rejection id: 1)
(node:23524) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In th
e future, promise rejections that are not handled will terminate the Node.js process with a n
on-zero exit code.
TypeError: Cannot read property 'txElapsedTime' of undefined
    at multipleTx (C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\client\cl-int
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at test (C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\client\cl-interacti
  • Your code does not make any sense with respect to your question. You can use await only inside an async function. The first line of code in your question does not abide to that rule. And since your question is specifically about this assignment becoming undefined, you need to explain exactly how you are doing things. This code will not even start running! – goodvibration Apr 28 '20 at 9:56
  • Oh i'm sorry these are just snippets of code i thought posting all of it would just be too messy. I am aware that await only works in async functions – Conviley Apr 28 '20 at 9:59
  • Of course you shouldn't post all of it, only what's relevant to your question. But this specific handling IS very much relevant. – goodvibration Apr 28 '20 at 10:01
  • I updated my post. Hopefully the specific handling is more clear now – Conviley Apr 28 '20 at 10:04
  • You are not calling function someAsyncFunc anywhere in your code! Even if you did, it is nor returning anything, not is it assigning any non-local variable. So what exactly is the purpose of this function, and how do you expect the local variable executionMetrics to have any meaning outside of it??? – goodvibration Apr 28 '20 at 11:02

As goodvibration pointed out in his comments this wasn't a ethereum or web3 problem but a pure javascript/basic programming error. The big mistake in the code was returning in the then()-statement and assuming that it would be the return value for executePromises(). That wasn't the case and i have corrected it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.