Skip to content

Commit

Permalink
Estimate transaction fee
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemKolodko committed Sep 27, 2023
1 parent da542f4 commit 6f5fa30
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/modules/payment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,20 @@ export class BotPayments {
}

private async getTransactionFee (): Promise<bn> {
const gasPrice = await this.web3.eth.getGasPrice()
return bn(gasPrice.toString()).multipliedBy(21000)
const estimatedFee = await this.estimateTransferFee()
return bn(estimatedFee)
}

private async estimateTransferFee() {

Check failure on line 203 in src/modules/payment/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing return type on function

Check failure on line 203 in src/modules/payment/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing space before function parentheses
const web3 = new Web3(this.rpcURL)
const gasPrice = await web3.eth.getGasPrice()
const txBody = {
from: this.holderAddress,
to: this.holderAddress,
value: web3.utils.toHex('0'),

Check failure on line 209 in src/modules/payment/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected trailing comma
}
const estimatedGas = await web3.eth.estimateGas(txBody)
return estimatedGas * +gasPrice
}

private async transferFunds (
Expand Down

0 comments on commit 6f5fa30

Please sign in to comment.