1
1
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'
3
3
import type { PrefixedHexString } from '@ethereumjs/util'
4
4
import { privateKeyToAccount } from 'web3-eth-accounts'
5
- import { toBigInt , toHex } from 'web3-utils'
6
5
import * as crypto from 'crypto'
7
6
8
7
type AccountType = {
@@ -56,10 +55,10 @@ export class Web3Accounts {
56
55
const stateManager = this . vmContext . vm ( ) . stateManager
57
56
const account = await stateManager . getAccount ( createAddressFromString ( addressStr ) )
58
57
if ( ! account ) {
59
- const account = new Account ( BigInt ( 0 ) , toBigInt ( balance || '0xf00000000000000001' ) )
58
+ const account = new Account ( BigInt ( 0 ) , BigInt ( balance || '0xf00000000000000001' ) )
60
59
await stateManager . putAccount ( createAddressFromString ( addressStr ) , account )
61
60
} else {
62
- account . balance = toBigInt ( balance || '0xf00000000000000001' )
61
+ account . balance = BigInt ( balance || '0xf00000000000000001' )
63
62
await stateManager . putAccount ( createAddressFromString ( addressStr ) , account )
64
63
}
65
64
} catch ( e ) {
@@ -106,9 +105,9 @@ export class Web3Accounts {
106
105
eth_getBalance ( payload , cb ) {
107
106
const address = payload . params [ 0 ]
108
107
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 ) )
112
111
} ) . catch ( ( error ) => {
113
112
cb ( error )
114
113
} )
@@ -131,7 +130,7 @@ export class Web3Accounts {
131
130
132
131
eth_chainId ( _payload , cb ) {
133
132
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
135
134
return cb ( null , id )
136
135
}
137
136
0 commit comments