Skip to content

Commit fe85c60

Browse files
committed
no web3 in remix-debug
1 parent 1f704aa commit fe85c60

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

libs/remix-debug/src/init.ts

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

5-
export function extendWeb3 (web3) {
6-
if (!web3.debug){
7-
web3.registerPlugin(new Web3DebugPlugin())
8-
}
9-
}
10-
11-
export function loadWeb3 (url) {
12-
if (!url) url = 'http://localhost:8545'
13-
const web3 = new Web3()
14-
web3.setProvider(new Web3.providers.HttpProvider(url))
15-
extendWeb3(web3)
16-
return web3
17-
}
18-
19-
export function setProvider (web3, url) {
20-
web3.setProvider(new web3.providers.HttpProvider(url))
4+
export function loadWeb3 (url = 'http://localhost:8545') {
5+
const provider = new ethers.JsonRpcProvider(url)
6+
extendProvider(provider)
7+
return provider
218
}
229

2310
export function web3DebugNode (network) {
@@ -35,32 +22,24 @@ export function web3DebugNode (network) {
3522
return null
3623
}
3724

38-
class Web3DebugPlugin extends Web3PluginBase {
39-
public pluginNamespace = 'debug'
25+
export function extendProvider (provider) { // Provider should be ethers.js provider
26+
27+
if (!provider.debug) provider.debug = {}
4028

41-
public preimage(key, cb) {
42-
this.requestManager.send({
43-
method: 'debug_preimage',
44-
params: [key]
45-
})
29+
provider.debug.preimage = (key, cb) => {
30+
this.send('debug_preimage', [key])
4631
.then(result => cb(null, result))
4732
.catch(error => cb(error))
4833
}
4934

50-
public traceTransaction(txHash, options, cb) {
51-
this.requestManager.send({
52-
method: 'debug_traceTransaction',
53-
params: [txHash, options]
54-
})
35+
provider.debug.traceTransaction = (txHash, options, cb) => {
36+
this.send('debug_traceTransaction', [txHash, options])
5537
.then(result => cb(null, result))
5638
.catch(error => cb(error))
5739
}
5840

59-
public storageRangeAt(txBlockHash, txIndex, address, start, maxSize, cb) {
60-
this.requestManager.send({
61-
method: 'debug_storageRangeAt',
62-
params: [txBlockHash, toNumber(txIndex), address, start, maxSize]
63-
})
41+
provider.debug.storageRangeAt = (txBlockHash, txIndex, address, start, maxSize, cb) => {
42+
this.send('debug_storageRangeAt', [txBlockHash, toNumber(txIndex), address, start, maxSize])
6443
.then(result => cb(null, result))
6544
.catch(error => cb(error))
6645
}

libs/remix-debug/test/vmCall.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
'use strict'
2-
import { extendWeb3 } from '../src/init'
2+
import { extendProvider } from '../src/init'
33
import { createAddressFromPrivateKey } from '@ethereumjs/util'
4-
import { Web3 } from 'web3';
5-
const { Provider } = require('@remix-project/remix-simulator')
4+
import { Provider } from '@remix-project/remix-simulator'
5+
import { ethers } from 'ethers'
66

77
async function getWeb3 () {
88
const remixSimulatorProvider = new Provider({ fork: 'cancun' })
99
await remixSimulatorProvider.init()
1010
await remixSimulatorProvider.Accounts.resetAccounts()
11-
const web3 = new Web3(remixSimulatorProvider)
12-
extendWeb3(web3)
13-
return web3
11+
const provider = new ethers.BrowserProvider(remixSimulatorProvider as any)
12+
extendProvider(provider)
13+
return provider
1414
}
1515

16-
async function sendTx (web3, from, to, value, data, cb) {
16+
async function sendTx (provider, from, to, value, data, cb) {
1717
try {
1818
cb = cb || (() => {})
19-
const receipt = await web3.eth.sendTransaction({
19+
const signer = await provider.getSigner()
20+
const receipt = await signer.sendTransaction({
2021
from: createAddressFromPrivateKey(from.privateKey).toString(),
2122
to,
2223
value,
2324
data,
2425
gas: 7000000
25-
}, null, { checkRevertBeforeSending: false, ignoreGasPricing: true })
26-
cb(null, receipt.transactionHash)
27-
return receipt.transactionHash
26+
})
27+
cb(null, receipt.hash)
28+
return receipt.hash
2829
} catch (e) {
2930
cb(e)
3031
}

0 commit comments

Comments
 (0)