Skip to content

Commit 72c67be

Browse files
committed
remix-sim web3-utils removal
1 parent c87b064 commit 72c67be

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

libs/remix-simulator/src/methods/accounts.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { signTypedData, SignTypedDataVersion, TypedMessage, MessageTypes } from '@metamask/eth-sig-util'
2-
import { privateToAddress, toChecksumAddress, isValidPrivate, createAddressFromString, toBytes, bytesToHex, Account } from '@ethereumjs/util'
2+
import { privateToAddress, toChecksumAddress, isValidPrivate, createAddressFromString, toBytes, bytesToHex, Account, intToHex } from '@ethereumjs/util'
33
import type { PrefixedHexString } from '@ethereumjs/util'
44
import { privateKeyToAccount } from 'web3-eth-accounts'
5-
import { toBigInt, toHex } from 'web3-utils'
65
import * as crypto from 'crypto'
76

87
type AccountType = {
@@ -56,10 +55,10 @@ export class Web3Accounts {
5655
const stateManager = this.vmContext.vm().stateManager
5756
const account = await stateManager.getAccount(createAddressFromString(addressStr))
5857
if (!account) {
59-
const account = new Account(BigInt(0), toBigInt(balance || '0xf00000000000000001'))
58+
const account = new Account(BigInt(0), BigInt(balance || '0xf00000000000000001'))
6059
await stateManager.putAccount(createAddressFromString(addressStr), account)
6160
} else {
62-
account.balance = toBigInt(balance || '0xf00000000000000001')
61+
account.balance = BigInt(balance || '0xf00000000000000001')
6362
await stateManager.putAccount(createAddressFromString(addressStr), account)
6463
}
6564
} catch (e) {
@@ -106,9 +105,9 @@ export class Web3Accounts {
106105
eth_getBalance (payload, cb) {
107106
const address = payload.params[0]
108107
this.vmContext.vm().stateManager.getAccount(createAddressFromString(address)).then((account) => {
109-
if (!account) return cb(null, toBigInt(0).toString(10))
110-
if (!account.balance) return cb(null, toBigInt(0).toString(10))
111-
cb(null, toBigInt(account.balance).toString(10))
108+
if (!account) return cb(null, BigInt(0).toString(10))
109+
if (!account.balance) return cb(null, BigInt(0).toString(10))
110+
cb(null, BigInt(account.balance).toString(10))
112111
}).catch((error) => {
113112
cb(error)
114113
})
@@ -131,7 +130,7 @@ export class Web3Accounts {
131130

132131
eth_chainId (_payload, cb) {
133132
if (!this.options.chainId) return cb(null, '0x539') // 0x539 is hex of 1337
134-
const id = (typeof this.options.chainId === 'number') ? toHex(this.options.chainId) : this.options.chainId
133+
const id = (typeof this.options.chainId === 'number') ? intToHex(this.options.chainId) : this.options.chainId
135134
return cb(null, id)
136135
}
137136

libs/remix-simulator/src/methods/blocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toHex } from 'web3-utils'
1+
import { hexlify } from 'ethers'
22
import { VMContext } from '../vm-context'
33
import { bigIntToHex, bytesToHex } from '@ethereumjs/util'
44

@@ -116,7 +116,7 @@ export class Blocks {
116116
blockHash: bytesToHex(block.hash()),
117117
blockNumber: bigIntToHex(block.header.number),
118118
from: receipt.from,
119-
gas: toHex(receipt.gas),
119+
gas: hexlify(receipt.gas),
120120
chainId: '0xd05',
121121
gasPrice: '0x4a817c800', // 20000000000
122122
hash: receipt.transactionHash,

libs/remix-simulator/src/methods/misc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sha3 } from 'web3-utils'
1+
import { keccak256 } from 'ethers'
22
const version = require('../../package.json').version
33

44
export function methods () {
@@ -39,7 +39,7 @@ export function eth_hashrate (payload, cb) {
3939

4040
export function web3_sha3 (payload, cb) {
4141
const str: string = payload.params[0]
42-
cb(null, sha3(str))
42+
cb(null, keccak256(str))
4343
}
4444

4545
export function eth_getCompilers (payload, cb) {

libs/remix-simulator/src/methods/transactions.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { toHex, toNumber, toBigInt } from 'web3-utils'
21
import { toChecksumAddress, bigIntToHex, bytesToHex, createAddressFromString } from '@ethereumjs/util'
32
import { processTx } from './txProcess'
43
import { execution } from '@remix-project/remix-lib'
5-
import { AbiCoder } from 'ethers'
4+
import { AbiCoder, toNumber } from 'ethers'
65
import { VMexecutionResult } from '@remix-project/remix-lib'
76
import { VMContext } from '../vm-context'
87
import { Log, EVMError } from '@ethereumjs/evm'
@@ -297,7 +296,7 @@ export class Transactions {
297296
const address = payload.params[0]
298297

299298
this.vmContext.vm().stateManager.getAccount(createAddressFromString(address)).then((account) => {
300-
const nonce = toBigInt(account.nonce).toString(10)
299+
const nonce = BigInt(account.nonce).toString(10)
301300
cb(null, nonce)
302301
}).catch((error) => {
303302
cb(error)
@@ -319,7 +318,7 @@ export class Transactions {
319318
blockHash: bytesToHex(txBlock.hash()),
320319
blockNumber: bigIntToHex(txBlock.header.number),
321320
from: receipt.from,
322-
gas: toHex(BigInt(receipt.gas)),
321+
gas: bigIntToHex(BigInt(receipt.gas)),
323322
chainId: '0xd05',
324323
// 'gasPrice': '2000000000000', // 0x123
325324
gasPrice: '0x4a817c800', // 20000000000
@@ -367,7 +366,7 @@ export class Transactions {
367366
blockHash: bytesToHex(txBlock.hash()),
368367
blockNumber: bigIntToHex(txBlock.header.number),
369368
from: receipt.from,
370-
gas: toHex(BigInt(receipt.gas)),
369+
gas: bigIntToHex(BigInt(receipt.gas)),
371370
chainId: '0xd05',
372371
// 'gasPrice': '2000000000000', // 0x123
373372
gasPrice: '0x4a817c800', // 20000000000
@@ -412,7 +411,7 @@ export class Transactions {
412411
blockHash: bytesToHex(txBlock.hash()),
413412
blockNumber: bigIntToHex(txBlock.header.number),
414413
from: receipt.from,
415-
gas: toHex(BigInt(receipt.gas)),
414+
gas: bigIntToHex(BigInt(receipt.gas)),
416415
// 'gasPrice': '2000000000000', // 0x123
417416
chainId: '0xd05',
418417
gasPrice: '0x4a817c800', // 20000000000

0 commit comments

Comments
 (0)