mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add error check for logs message
This commit is contained in:
parent
36733da271
commit
315942db41
@ -2,3 +2,5 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
|||||||
export const GASLIMIT_DEFAULT = 1000000
|
export const GASLIMIT_DEFAULT = 1000000
|
||||||
export const MAX_UINT_256 =
|
export const MAX_UINT_256 =
|
||||||
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
||||||
|
export const FEE_HISTORY_NOT_SUPPORTED =
|
||||||
|
'Returned error: Method eth_feeHistory not supported.'
|
||||||
|
@ -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, LoggerInstance } from '.'
|
import { minAbi, GASLIMIT_DEFAULT, LoggerInstance, FEE_HISTORY_NOT_SUPPORTED } from '.'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
|
|
||||||
export function setContractDefaults(contract: Contract, config: Config): Contract {
|
export function setContractDefaults(contract: Contract, config: Config): Contract {
|
||||||
@ -110,21 +110,28 @@ export async function sendTx(
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const feeHistory = await web3.eth.getFeeHistory(1, 'latest', [75])
|
const feeHistory = await web3.eth.getFeeHistory(1, 'latest', [75])
|
||||||
let aggressiveFee = new BigNumber(feeHistory?.reward?.[0]?.[0])
|
if (feeHistory && feeHistory?.baseFeePerGas?.[0] && feeHistory?.reward?.[0]?.[0]) {
|
||||||
if (gasFeeMultiplier > 1) {
|
let aggressiveFee = new BigNumber(feeHistory?.reward?.[0]?.[0])
|
||||||
aggressiveFee = aggressiveFee.multipliedBy(gasFeeMultiplier)
|
if (gasFeeMultiplier > 1) {
|
||||||
|
aggressiveFee = aggressiveFee.multipliedBy(gasFeeMultiplier)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendTxValue.maxPriorityFeePerGas = aggressiveFee
|
||||||
|
.integerValue(BigNumber.ROUND_DOWN)
|
||||||
|
.toString(10)
|
||||||
|
|
||||||
|
sendTxValue.maxFeePerGas = aggressiveFee
|
||||||
|
.plus(new BigNumber(feeHistory?.baseFeePerGas?.[0]).multipliedBy(2))
|
||||||
|
.integerValue(BigNumber.ROUND_DOWN)
|
||||||
|
.toString(10)
|
||||||
|
} else {
|
||||||
|
sendTxValue.gasPrice = await getFairGasPrice(web3, gasFeeMultiplier)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendTxValue.maxPriorityFeePerGas = aggressiveFee
|
|
||||||
.integerValue(BigNumber.ROUND_DOWN)
|
|
||||||
.toString(10)
|
|
||||||
|
|
||||||
sendTxValue.maxFeePerGas = aggressiveFee
|
|
||||||
.plus(new BigNumber(feeHistory?.baseFeePerGas?.[0]).multipliedBy(2))
|
|
||||||
.integerValue(BigNumber.ROUND_DOWN)
|
|
||||||
.toString(10)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
LoggerInstance.error('Not able to use EIP 1559.')
|
err?.message === FEE_HISTORY_NOT_SUPPORTED &&
|
||||||
|
LoggerInstance.log(
|
||||||
|
'Not able to use EIP 1559, getFeeHistory method not suported by network.'
|
||||||
|
)
|
||||||
sendTxValue.gasPrice = await getFairGasPrice(web3, gasFeeMultiplier)
|
sendTxValue.gasPrice = await getFairGasPrice(web3, gasFeeMultiplier)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user