Skip to content

Commit

Permalink
updated gasfee() method for gas estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainLEVI-XXX committed Nov 30, 2023
1 parent 1aa6c82 commit 9bc5252
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@

### 1.0.7 (2023-07-05)

- cleaned package structure
- cleaned package structure

### 1.0.8 (2023-11-30)

- Updated gasFee() method for type 1 transactions and added its test.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getsafle/vault-arbitrum-controller",
"version": "1.0.7",
"version": "1.0.8",
"description": "arbitrum controller for safle vault",
"engines": {
"node": ">= 10"
Expand Down
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,14 @@ class KeyringController extends EventEmitter {
return { transactionDetails: receipt.transactionHash }
}

async getFees(arbitrumTx, web3) {
const { from, to, value, data, gasLimit } = arbitrumTx
const estimate = gasLimit ? gasLimit : await web3.eth.estimateGas({ to, from, value, data })
async getFees(velasTx, web3) {
const { from, to, value, data, manualLimit } = velasTx
const gasLimit = manualLimit ? manualLimit : await web3.eth.estimateGas({ to, from, value, data })
const gasPrice = await web3.eth.getGasPrice();
return { transactionFees: estimate * gasPrice }
return {
gasLimit: gasLimit,
gasPrice: parseInt(gasPrice)
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ describe('Initialize wallet ', () => {
console.log(" get balance ", balance, accounts)
})

it("Get fees for a arbitrum tx", async () => {
const accounts = await arbitrumKeyring.getAccounts()
const web3 = new Web3(TESTNET.URL);
const tx = {
from: accounts[0],
to: '0x641BB2596D8c0b32471260712566BF933a2f1a8e',
value: 0,
data: "0x00"
}
const getEstimate = await arbitrumKeyring.getFees(tx, web3)
console.log(" get gas estimate ", getEstimate)
})

it("sign Transaction ", async () => {

const accounts = await arbitrumKeyring.getAccounts()
Expand Down

0 comments on commit 9bc5252

Please sign in to comment.