Skip to content

Commit 9945adc

Browse files
committed
use ethers.js for estimateGas & fix listening env change
1 parent f386a8c commit 9945adc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

libs/remix-lib/src/execution/txRunnerWeb3.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EventManager } from '../eventManager'
33
import type { Transaction as InternalTransaction } from './txRunner'
44
import { Web3 } from 'web3'
55
import { toBigInt, toHex } from 'web3-utils'
6+
import { ethers } from 'ethers'
67

78
export class TxRunnerWeb3 {
89
event
@@ -134,9 +135,11 @@ export class TxRunnerWeb3 {
134135
txCopy.gasPrice = undefined
135136
}
136137
}
137-
this.getWeb3().eth.estimateGas(txCopy)
138-
.then(gasEstimation => {
138+
const ethersProvider = new ethers.providers.Web3Provider(this.getWeb3().currentProvider as any)
139+
ethersProvider.estimateGas(txCopy)
140+
.then(gasEstimationBigInt => {
139141
gasEstimationForceSend(null, () => {
142+
const gasEstimation = gasEstimationBigInt.toNumber()
140143
/*
141144
* gasLimit is a value that can be set in the UI to hardcap value that can be put in a tx.
142145
* e.g if the gasestimate

libs/remix-ui/run-tab/src/lib/components/dropdownLabel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export function DropdownLabel({ label, bridges, currentProvider, chainId, runTab
3131
}
3232
}
3333
checkEnvLabels()
34-
const selectedEnv = selectedEnvs.find(env => (env.chainId === chainId && env.value === runTabState.selectExEnv) || (env.value === 'walletconnect' && env.value === currentProvider?.name) || env.chainId === chainId)
34+
const selectedEnv = selectedEnvs.find(env => (env.chainId === chainId && env.value === runTabState.selectExEnv) || (env.value === 'walletconnect' && env.value === currentProvider?.name))
3535
if (selectedEnv) {
3636
setRenderLabel(selectedEnv.name)
3737
setExecutionEnv({ context: selectedEnv.value })
3838
} else {
3939
setRenderLabel('Injected Provider - MetaMask')
4040
}
41-
}, [chainId])
41+
}, [chainId, currentProvider && currentProvider.name])
4242

4343
return (
4444
<>

0 commit comments

Comments
 (0)