Skip to content

Commit

Permalink
Add confirmations to TransactionResponse (ethers-io#4094).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent 4402ec8 commit bb9ddb9
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 bb9ddb9

Please sign in to comment.