Skip to content

Commit

Permalink
calculate gas cost per transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuvlad-innovatorspark committed Jan 31, 2024
1 parent cdbc926 commit 7ac9cef
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/modules/smart-contract/smart-contract.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class SmartContractService {
this.appConfigService.smartContractPrivateKey,
);

const gasPrice = await this.web3.eth.getGasPrice();

const response = await this.wiiqareContract.methods
.mintVoucher([
amount,
Expand All @@ -55,7 +57,8 @@ export class SmartContractService {
])
.send({
from: this.wiiQareAccount.address,
gasPrice: "200000000000"
gasPrice: gasPrice,
gas: 500000
});

logInfo(`response -> ${response}`);
Expand Down Expand Up @@ -137,6 +140,7 @@ export class SmartContractService {
const rr: AddedAccount = this.web3.eth.accounts.wallet.add(
this.appConfigService.smartContractPrivateKey,
);
const gasPrice = await this.web3.eth.getGasPrice();

const result = await this.wiiqareContract.methods
.alterVoucher(voucherId, [
Expand All @@ -149,7 +153,8 @@ export class SmartContractService {
])
.call({
from: this.wiiQareAccount.address,
gasPrice: "200000000000"
gasPrice: gasPrice,
gas: 500000
});

return result;
Expand Down Expand Up @@ -185,14 +190,16 @@ export class SmartContractService {
const rr = this.web3.eth.accounts.wallet.add(
this.appConfigService.smartContractPrivateKey,
);
const gasPrice = await this.web3.eth.getGasPrice();

const response = await this.wiiqareContract.methods
.burn(
voucherID
)
.send({
from: this.wiiQareAccount.address,
gasPrice: "200000000000"
gasPrice: gasPrice,
gas: 500000
});

logInfo(`response -> ${response}`);
Expand Down

0 comments on commit 7ac9cef

Please sign in to comment.