Skip to content

Commit

Permalink
Add confirmations to TransactionResponse (#4094).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jun 7, 2023
1 parent 3c1bad2 commit bb8685b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src.ts/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,26 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
return this.provider.getTransaction(this.hash);
}

/**
* Resolve to the number of confirmations this transaction has.
*/
async confirmations(): Promise<number> {
if (this.blockNumber == null) {
const { tx, blockNumber } = await resolveProperties({
tx: this.getTransaction(),
blockNumber: this.provider.getBlockNumber()
});

// Not mined yet...
if (tx == null || tx.blockNumber == null) { return 0; }

return blockNumber - tx.blockNumber + 1;
}

const blockNumber = await this.provider.getBlockNumber();
return blockNumber - this.blockNumber + 1;
}

/**
* Resolves once this transaction has been mined and has
* %%confirms%% blocks including it (default: ``1``) with an
Expand Down

0 comments on commit bb8685b

Please sign in to comment.