@getsafle/vault-polygon-controller
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -24,1 +24,7 @@ ### 1.0.0 (2021-12-1) | ||
- Added sign() to sign a message or transaction and get signature along with v,r,s. | ||
### 1.2.1 (2022-04-13) | ||
##### Updated getFees() | ||
- Updated getFees() function to calculate the transaction fees using `maxFeePerGas` since polygon supports type 2 transactions. |
{ | ||
"name": "@getsafle/vault-polygon-controller", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -520,7 +520,13 @@ | ||
async getFees(polygonTx, web3) { | ||
const { from, to, value, data, gasLimit } = polygonTx | ||
const estimate = gasLimit ? gasLimit : await web3.eth.estimateGas({ to, from, value, data }) | ||
const gasPrice = await web3.eth.getGasPrice(); | ||
return { transactionFees: estimate * gasPrice } | ||
async getFees(rawTx, web3) { | ||
const { from, to, value, data, gasLimit, maxFeePerGas } = rawTx | ||
const estimate = gasLimit ? gasLimit : await web3.eth.estimateGas({ to, from, value, data }); | ||
const re = /[0-9A-Fa-f]{6}/g; | ||
const maxFee = (re.test(maxFeePerGas)) ? parseInt(maxFeePerGas, 16) : maxFeePerGas; | ||
const gas = (re.test(estimate)) ? parseInt(estimate, 16) : estimate | ||
return { transactionFees: web3.utils.fromWei((gas * maxFee).toString(), 'ether') } | ||
} | ||
@@ -527,0 +533,0 @@ } |
@@ -108,3 +108,5 @@ var assert = require('assert'); | ||
value: POLYGON_AMOUNT_TO_CONTRACT, | ||
data | ||
data, | ||
maxFeePerGas: 2500000002, | ||
maxPriorityFeePerGas: 2500000000 | ||
} | ||
@@ -127,3 +129,5 @@ | ||
const tx = { | ||
gasLimit: 2100 | ||
gasLimit: 2100, | ||
maxFeePerGas: 2500000002, | ||
maxPriorityFeePerGas: 2500000000 | ||
} | ||
@@ -130,0 +134,0 @@ const fees = await polygonKeyring.getFees(tx, web3) |
324246
7992