Skip to content

Commit a43ebb6

Browse files
authored
Merge pull request #6409 from remix-project-org/removeWeb3
remove web3js dependency
2 parents d4a7f63 + ca2acf5 commit a43ebb6

File tree

141 files changed

+861
-1770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+861
-1770
lines changed

apps/debugger/src/app/debugger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class DebuggerClientApi extends DebuggerApiMixin(PluginClient) {
2323
fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise<CompilerAbstract>
2424
getFile: (path: string) => Promise<string>
2525
setFile: (path: string, content: string) => Promise<void>
26-
getDebugWeb3: () => any // returns an instance of web3.js, if applicable (mainet, goerli, ...) it returns a reference to a node from devops (so we are sure debug endpoint is available)
26+
getDebugProvider: () => any // returns an instance of web3.js, if applicable (mainnet, goerli, ...) it returns a reference to a node from devops (so we are sure debug endpoint is available)
2727
web3: () => any // returns an instance of web3.js
2828
onStartDebugging: (debuggerBackend: any) => void // called when debug starts
2929
onStopDebugging: () => void // called when debug stops

apps/remix-dapp/src/actions/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import axios from 'axios';
2-
import Web3 from 'web3';
3-
import { AbiCoder } from 'ethers';
2+
import { AbiCoder, parseUnits } from 'ethers';
43
import BN from 'bn.js';
54
import { execution } from '@remix-project/remix-lib';
65
import { toBytes, addHexPrefix } from '@ethereumjs/util';
@@ -126,7 +125,7 @@ export const runTransactions = async (payload: any) => {
126125
console.log(payload);
127126
const { sendValue, sendUnit, gasLimit, selectedAccount } = state.settings;
128127
const { address, decodedResponse, name } = state.instance;
129-
const value = Web3.utils.toWei(sendValue, sendUnit);
128+
const value = parseUnits(sendValue, sendUnit);
130129

131130
const tx = {
132131
to: address,

apps/remix-dapp/src/utils/txRunner.ts

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import Web3, {
2-
FMT_NUMBER,
3-
type EthExecutionAPI,
4-
type SupportedProviders,
5-
FMT_BYTES,
6-
type Bytes,
7-
} from 'web3';
81
import { addHexPrefix, toBytes } from '@ethereumjs/util';
92
import { execution } from '@remix-project/remix-lib';
10-
import { toBigInt } from 'web3-utils';
113
import { saveSettings } from '../actions';
4+
import { BrowserProvider, ethers, formatUnits, toNumber, TransactionReceipt, TransactionResponse } from 'ethers'
125

13-
const web3 = new Web3();
6+
const provider = ethers.getDefaultProvider()
147

158
export const shortenAddress = (address: string, etherBalance?: string) => {
169
const len = address.length;
@@ -29,12 +22,9 @@ async function pause() {
2922
});
3023
}
3124

32-
async function tryTillReceiptAvailable(txhash: Bytes) {
25+
async function tryTillReceiptAvailable(txhash) {
3326
try {
34-
const receipt = await web3.eth.getTransactionReceipt(txhash, {
35-
number: FMT_NUMBER.NUMBER,
36-
bytes: FMT_BYTES.HEX,
37-
});
27+
const receipt: TransactionReceipt = await provider.getTransactionReceipt(txhash);
3828
if (receipt) {
3929
if (!receipt.to && !receipt.contractAddress) {
4030
// this is a contract creation and the receipt doesn't contain a contract address. we have to keep polling...
@@ -52,12 +42,9 @@ async function tryTillReceiptAvailable(txhash: Bytes) {
5242
return await tryTillReceiptAvailable(txhash);
5343
}
5444

55-
async function tryTillTxAvailable(txhash: Bytes) {
45+
async function tryTillTxAvailable(txhash) {
5646
try {
57-
const tx = await web3.eth.getTransaction(txhash, {
58-
number: FMT_NUMBER.NUMBER,
59-
bytes: FMT_BYTES.HEX,
60-
});
47+
const tx: TransactionResponse = await provider.getTransaction(txhash, );
6148
if (tx?.blockHash) return tx;
6249
return tx;
6350
} catch (e) {
@@ -90,16 +77,13 @@ export class TxRunner {
9077
}, 30000);
9178
}
9279

93-
setProvider(
94-
provider: string | SupportedProviders<EthExecutionAPI> | undefined
95-
) {
96-
web3.setProvider(provider);
80+
setProvider(provider) {
81+
new ethers.BrowserProvider(provider)
9782
}
9883

9984
getAccounts() {
10085
saveSettings({ isRequesting: true });
101-
void web3.eth
102-
.getAccounts()
86+
(provider as any).send("eth_requestAccounts", [])
10387
.then(async (accounts) => {
10488
const loadedAccounts: any = {};
10589
for (const account of accounts) {
@@ -115,17 +99,18 @@ export class TxRunner {
11599
}
116100

117101
async getBalanceInEther(address: string) {
118-
const balance = await web3.eth.getBalance(address);
119-
return Web3.utils.fromWei(balance.toString(10), 'ether');
102+
const balance = await provider.getBalance(address);
103+
return formatUnits(balance.toString(10), 'ether');
120104
}
121105

122106
async getGasPrice() {
123-
return await web3.eth.getGasPrice();
107+
const { gasPrice } = await provider.getFeeData()
108+
return gasPrice;
124109
}
125110

126111
async runTx(tx: any, gasLimit: any, useCall: boolean) {
127112
if (useCall) {
128-
const returnValue = await web3.eth.call({ ...tx, gas: gasLimit });
113+
const returnValue = await provider.call({ ...tx, gasLimit });
129114

130115
return toBytes(addHexPrefix(returnValue));
131116
}
@@ -147,8 +132,8 @@ export class TxRunner {
147132
txCopy.maxFeePerGas = Math.ceil(
148133
Number(
149134
(
150-
toBigInt(network.lastBlock.baseFeePerGas) +
151-
toBigInt(network.lastBlock.baseFeePerGas) / BigInt(3)
135+
BigInt(network.lastBlock.baseFeePerGas) +
136+
BigInt(network.lastBlock.baseFeePerGas) / BigInt(3)
152137
).toString()
153138
)
154139
);
@@ -159,8 +144,8 @@ export class TxRunner {
159144
}
160145

161146
try {
162-
const gasEstimation = await web3.eth.estimateGas(txCopy);
163-
tx.gas = !gasEstimation ? gasLimit : gasEstimation;
147+
const gasEstimation = await provider.estimateGas(txCopy);
148+
tx.gasLimit = !gasEstimation ? gasLimit : gasEstimation;
164149
return await this._executeTx(tx, network);
165150
} catch (error) {
166151
console.log(error);
@@ -169,7 +154,8 @@ export class TxRunner {
169154
}
170155

171156
async detectNetwork() {
172-
const id = Number(await web3.eth.net.getId());
157+
const { chainId } = await provider.getNetwork()
158+
const id = Number(chainId)
173159
let name = '';
174160
if (id === 1) name = 'Main';
175161
else if (id === 3) name = 'Ropsten';
@@ -180,7 +166,7 @@ export class TxRunner {
180166
else name = 'Custom';
181167

182168
if (id === 1) {
183-
const block = await web3.eth.getBlock(0);
169+
const block = await provider.getBlock(0);
184170
if (block && block.hash !== this.mainNetGenesisHash) name = 'Custom';
185171
return {
186172
id,
@@ -205,18 +191,18 @@ export class TxRunner {
205191

206192
async _updateChainContext() {
207193
try {
208-
const block = await web3.eth.getBlock('latest');
194+
const block = await provider.getBlock('latest');
209195
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
210196
this.blockGasLimit = block?.gasLimit
211197
? Math.floor(
212-
Number(web3.utils.toNumber(block.gasLimit)) -
213-
(5 * Number(web3.utils.toNumber(block.gasLimit))) / 1024
198+
Number(toNumber(block.gasLimit)) -
199+
(5 * Number(toNumber(block.gasLimit))) / 1024
214200
)
215-
: web3.utils.toNumber(this.blockGasLimitDefault);
201+
: toNumber(this.blockGasLimitDefault);
216202
this.lastBlock = block;
217203
try {
218204
this.currentFork = execution.forkAt(
219-
await web3.eth.net.getId(),
205+
(await provider.getNetwork()).chainId,
220206
block.number
221207
);
222208
} catch (e) {
@@ -247,19 +233,16 @@ export class TxRunner {
247233

248234
let currentDateTime = new Date();
249235
try {
250-
const { transactionHash } = await web3.eth.sendTransaction(
251-
tx,
252-
undefined,
253-
{ checkRevertBeforeSending: false, ignoreGasPricing: true }
254-
);
255-
const receipt = await tryTillReceiptAvailable(transactionHash);
256-
tx = await tryTillTxAvailable(transactionHash);
236+
const signer = await (provider as BrowserProvider).getSigner(tx.from || 0);
237+
const { hash } = await signer.sendTransaction(tx);
238+
const receipt = await tryTillReceiptAvailable(hash);
239+
tx = await tryTillTxAvailable(hash);
257240

258241
currentDateTime = new Date();
259242
return {
260243
receipt,
261244
tx,
262-
transactionHash: receipt ? receipt.transactionHash : null,
245+
transactionHash: receipt ? receipt.hash : null,
263246
};
264247
} catch (error: any) {
265248
console.log(

apps/remix-ide-e2e/src/tests/ballot.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
3535
.testFunction('last',
3636
{
37-
status: '0x1 Transaction mined and execution succeed',
37+
status: '1 Transaction mined and execution succeed',
3838
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
3939
})
4040
},
@@ -87,7 +87,7 @@ module.exports = {
8787
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
8888
.testFunction('last',
8989
{
90-
status: '0x0 Transaction mined but execution failed',
90+
status: '0 Transaction mined but execution failed',
9191
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
9292
})
9393
},

apps/remix-ide-e2e/src/tests/ballot_0_4_14.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
4444
.testFunction('last',
4545
{
46-
status: '0x1 Transaction mined and execution succeed',
46+
status: '1 Transaction mined and execution succeed',
4747
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
4848
})
4949
},
@@ -82,7 +82,7 @@ module.exports = {
8282
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
8383
.testFunction('last',
8484
{
85-
status: '0x1 Transaction mined and execution succeed',
85+
status: '1 Transaction mined and execution succeed',
8686
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
8787
})
8888
},

apps/remix-ide-e2e/src/tests/compile_run_widget.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222

2323
'Run script using the widget #group2': function (browser: NightwatchBrowser) {
2424
browser
25-
.openFile('scripts/deploy_with_web3.ts')
25+
.openFile('scripts/deploy_with_ethers.ts')
2626
.click('[data-id="compile-action"]')
2727
.waitForElementVisible('[data-id="compile_group"] i.fa-check', 10000)
2828
},

apps/remix-ide-e2e/src/tests/eip1153.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
.clickFunction('useTransientStorage - transact (not payable)')
2626
.testFunction('last',
2727
{
28-
status: '0x1 Transaction mined and execution succeed',
28+
status: '1 Transaction mined and execution succeed',
2929
'decoded output': {
3030
0: 'uint256: out1 14',
3131
1: 'uint256: out2 15'

apps/remix-ide-e2e/src/tests/environment-account.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
.assert.containsText({
3434
selector: '[data-id^="txOriginSelectAccountItem-"]',
3535
index: 0
36-
}, '100 ETH')
36+
}, '100.0 ETH')
3737
.end()
3838
}
3939
}

apps/remix-ide-e2e/src/tests/erc721.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = {
4242
.createContract('')
4343
.testFunction('last',
4444
{
45-
status: '0x1 Transaction mined and execution succeed',
45+
status: '1 Transaction mined and execution succeed',
4646
'decoded input': {}
4747
}).end()
4848
}

apps/remix-ide-e2e/src/tests/metamask.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ const tests = {
207207

208208
.testFunction('last',
209209
{
210-
status: '0x1 Transaction mined and execution succeed',
210+
status: '1 Transaction mined and execution succeed',
211211
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
212212
})
213213
},

0 commit comments

Comments
 (0)