Skip to content

Commit 1f704aa

Browse files
committed
no web3 in remix-lib
1 parent 4de51d4 commit 1f704aa

File tree

3 files changed

+29
-48
lines changed

3 files changed

+29
-48
lines changed

libs/remix-lib/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"rlp": "^3.0.0",
3030
"solc": "0.8.26",
3131
"string-similarity": "^4.0.4",
32-
"viem": "2.22.3",
33-
"web3": "^4.1.1"
32+
"viem": "2.22.3"
3433
},
3534
"devDependencies": {
3635
"@babel/core": "^7.4.5",

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict'
22
import { EventManager } from '../eventManager'
33
import type { Transaction as InternalTransaction } from './txRunner'
4-
import { Web3 } from 'web3'
5-
import { BrowserProvider, getAddress } from 'ethers'
4+
import { BrowserProvider, getAddress, parseUnits } from 'ethers'
65
import { normalizeHexAddress } from '../helpers/uiHelper'
76
import { aaSupportedNetworks, aaLocalStorageKey, getPimlicoBundlerURL, aaDeterminiticProxyAddress } from '../helpers/aaConstants'
87
import { randomBytes } from 'crypto'
@@ -17,7 +16,7 @@ const { createPimlicoClient } = require("permissionless/clients/pimlico")
1716
export class TxRunnerWeb3 {
1817
event
1918
_api
20-
getWeb3: () => Web3
19+
getWeb3: () => BrowserProvider
2120
currentblockGasLimit: () => number
2221

2322
constructor (api, getWeb3, currentblockGasLimit) {
@@ -37,11 +36,11 @@ export class TxRunnerWeb3 {
3736
}
3837
if (txFee) {
3938
if (txFee.baseFeePerGas) {
40-
tx.maxPriorityFeePerGas = toHex(BigInt(this.getWeb3().utils.toWei(txFee.maxPriorityFee, 'gwei')))
41-
tx.maxFeePerGas = toHex(BigInt(this.getWeb3().utils.toWei(txFee.maxFee, 'gwei')))
39+
tx.maxPriorityFeePerGas = toHex(BigInt(parseUnits(txFee.maxPriorityFee, 'gwei')))
40+
tx.maxFeePerGas = toHex(BigInt(parseUnits(txFee.maxFee, 'gwei')))
4241
tx.type = '0x2'
4342
} else {
44-
tx.gasPrice = toHex(BigInt(this.getWeb3().utils.toWei(txFee.gasPrice, 'gwei')))
43+
tx.gasPrice = toHex(BigInt(parseUnits(txFee.gasPrice, 'gwei')))
4544
// tx.type = '0x1'
4645
}
4746
if (tx.authorizationList) {
@@ -97,8 +96,8 @@ export class TxRunnerWeb3 {
9796
promptCb(
9897
async (value) => {
9998
try {
100-
const res = await (this.getWeb3() as any).eth.personal.sendTransaction({ ...tx, value }, { checkRevertBeforeSending: false, ignoreGasPricing: true })
101-
cb(null, res.transactionHash, isCreation, false, null)
99+
const res = await (await this.getWeb3().getSigner()).sendTransaction({ ...tx, value })
100+
cb(null, res.hash, isCreation, false, null)
102101

103102
} catch (e) {
104103
console.log(`Send transaction failed: ${e.message || e.error} . if you use an injected provider, please check it is properly unlocked. `)
@@ -118,8 +117,8 @@ export class TxRunnerWeb3 {
118117
const { txHash, contractAddress } = await this.sendUserOp(tx, network.id)
119118
cb(null, txHash, isCreation, true, contractAddress)
120119
} else {
121-
const res = await this.getWeb3().eth.sendTransaction(tx, null, { checkRevertBeforeSending: false, ignoreGasPricing: true })
122-
cb(null, res.transactionHash, isCreation, false, null)
120+
const res = await (await this.getWeb3().getSigner()).sendTransaction(tx)
121+
cb(null, res.hash, isCreation, false, null)
123122
}
124123
} catch (e) {
125124
if (!e.message) e.message = ''
@@ -146,7 +145,7 @@ export class TxRunnerWeb3 {
146145
if (this._api && this._api.isVM()) {
147146
(this.getWeb3() as any).remix.registerCallId(timestamp)
148147
}
149-
this.getWeb3().eth.call(tx)
148+
this.getWeb3().call(tx)
150149
.then((result: any) => callback(null, {
151150
result: result
152151
}))
@@ -170,7 +169,7 @@ export class TxRunnerWeb3 {
170169
txCopy.gasPrice = undefined
171170
}
172171
}
173-
const ethersProvider = new BrowserProvider(this.getWeb3().currentProvider as any)
172+
const ethersProvider = this.getWeb3()
174173
ethersProvider.estimateGas(txCopy)
175174
.then(gasEstimationBigInt => {
176175
gasEstimationForceSend(null, () => {
@@ -322,9 +321,9 @@ export class TxRunnerWeb3 {
322321
}
323322
}
324323

325-
async function tryTillReceiptAvailable (txhash: string, web3: Web3) {
324+
async function tryTillReceiptAvailable (txhash: string, provider: BrowserProvider) {
326325
try {
327-
const receipt = await web3.eth.getTransactionReceipt(txhash)
326+
const receipt = await provider.getTransactionReceipt(txhash)
328327
if (receipt) {
329328
if (!receipt.to && !receipt.contractAddress) {
330329
// this is a contract creation and the receipt doesn't contain a contract address. we have to keep polling...
@@ -334,15 +333,15 @@ async function tryTillReceiptAvailable (txhash: string, web3: Web3) {
334333
}
335334
} catch (e) {}
336335
await pause()
337-
return await tryTillReceiptAvailable(txhash, web3)
336+
return await tryTillReceiptAvailable(txhash, provider)
338337
}
339338

340-
async function tryTillTxAvailable (txhash: string, web3: Web3) {
339+
async function tryTillTxAvailable (txhash: string, provider: BrowserProvider) {
341340
try {
342-
const tx = await web3.eth.getTransaction(txhash)
341+
const tx = await provider.getTransaction(txhash)
343342
if (tx && tx.blockHash) return tx
344343
} catch (e) {}
345-
return await tryTillTxAvailable(txhash, web3)
344+
return await tryTillTxAvailable(txhash, provider)
346345
}
347346

348347
async function pause () { return new Promise((resolve, reject) => { setTimeout(resolve, 500) }) }

libs/remix-lib/src/init.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,29 @@
11
'use strict'
2-
import { Web3, Web3PluginBase } from 'web3'
3-
import { toNumber } from 'ethers'
2+
import { toNumber, ethers } from 'ethers'
43

5-
export function extendWeb3 (web3) {
6-
if (!web3.debug){
7-
web3.registerPlugin(new Web3DebugPlugin())
8-
}
9-
}
104

115
export function loadWeb3 (url = 'http://localhost:8545') {
12-
const web3 = new Web3()
13-
web3.setProvider(new Web3.providers.HttpProvider(url))
14-
extendWeb3(web3)
15-
return web3
6+
const provider = new ethers.JsonRpcProvider(url)
7+
extendWeb3(provider)
8+
return provider
169
}
1710

18-
class Web3DebugPlugin extends Web3PluginBase {
19-
public pluginNamespace = 'debug'
11+
export function extendWeb3 (provider) { // Provider should be ethers.js provider
2012

21-
public preimage(key, cb) {
22-
this.requestManager.send({
23-
method: 'debug_preimage',
24-
params: [key]
25-
})
13+
provider.debug.preimage = (key, cb) => {
14+
this.send('debug_preimage', [key])
2615
.then(result => cb(null, result))
2716
.catch(error => cb(error))
2817
}
2918

30-
public traceTransaction(txHash, options, cb) {
31-
this.requestManager.send({
32-
method: 'debug_traceTransaction',
33-
params: [txHash, options]
34-
})
19+
provider.debug.traceTransaction = (txHash, options, cb) => {
20+
this.send('debug_traceTransaction', [txHash, options])
3521
.then(result => cb(null, result))
3622
.catch(error => cb(error))
3723
}
3824

39-
public storageRangeAt(txBlockHash, txIndex, address, start, maxSize, cb) {
40-
this.requestManager.send({
41-
method: 'debug_storageRangeAt',
42-
params: [txBlockHash, toNumber(txIndex), address, start, maxSize]
43-
})
25+
provider.debug.storageRangeAt = (txBlockHash, txIndex, address, start, maxSize, cb) => {
26+
this.send('debug_storageRangeAt', [txBlockHash, toNumber(txIndex), address, start, maxSize])
4427
.then(result => cb(null, result))
4528
.catch(error => cb(error))
4629
}

0 commit comments

Comments
 (0)