mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
use try catch in sendTx
This commit is contained in:
parent
7941829ad6
commit
8b1842e1e9
@ -2,7 +2,7 @@ import Web3 from 'web3'
|
|||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { Config } from '../config'
|
import { Config } from '../config'
|
||||||
import { minAbi, GASLIMIT_DEFAULT } from '.'
|
import { minAbi, GASLIMIT_DEFAULT, LoggerInstance } from '.'
|
||||||
|
|
||||||
export function setContractDefaults(contract: Contract, config: Config): Contract {
|
export function setContractDefaults(contract: Contract, config: Config): Contract {
|
||||||
if (config) {
|
if (config) {
|
||||||
@ -116,17 +116,18 @@ export async function sendTx(
|
|||||||
from: from,
|
from: from,
|
||||||
gas: estGas + 1
|
gas: estGas + 1
|
||||||
}
|
}
|
||||||
const feeHistory = await web3.eth.getFeeHistory(1, 'pending', [75])
|
try {
|
||||||
if (feeHistory && feeHistory.baseFeePerGas && feeHistory.reward[0][0]) {
|
const feeHistory = await web3.eth.getFeeHistory(1, 'pending', [75])
|
||||||
sendTxValue.maxPriorityFeePerGas = new BigNumber(feeHistory.reward[0][0])
|
sendTxValue.maxPriorityFeePerGas = new BigNumber(feeHistory?.reward?.[0]?.[0])
|
||||||
.integerValue(BigNumber.ROUND_DOWN)
|
.integerValue(BigNumber.ROUND_DOWN)
|
||||||
.toString(10)
|
.toString(10)
|
||||||
|
|
||||||
sendTxValue.maxFeePerGas = new BigNumber(feeHistory.reward[0][0])
|
sendTxValue.maxFeePerGas = new BigNumber(feeHistory?.reward?.[0]?.[0])
|
||||||
.plus(new BigNumber(feeHistory.baseFeePerGas[0]).multipliedBy(2))
|
.plus(new BigNumber(feeHistory?.baseFeePerGas?.[0]).multipliedBy(2))
|
||||||
.integerValue(BigNumber.ROUND_DOWN)
|
.integerValue(BigNumber.ROUND_DOWN)
|
||||||
.toString(10)
|
.toString(10)
|
||||||
} else {
|
} catch (err) {
|
||||||
|
LoggerInstance.log('EIP 1559 not supported by network')
|
||||||
sendTxValue.gasPrice = await this.getFairGasPrice()
|
sendTxValue.gasPrice = await this.getFairGasPrice()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user