@@ -5,7 +5,7 @@ import type { ThirdwebClient } from "../../../../client/client.js";
55import { eth_sendRawTransaction } from "../../../../rpc/actions/eth_sendRawTransaction.js" ;
66import { getRpcClient } from "../../../../rpc/rpc.js" ;
77import { getAddress } from "../../../../utils/address.js" ;
8- import { type Hex , toHex } from "../../../../utils/encoding/hex.js" ;
8+ import { type Hex , isHex , toHex } from "../../../../utils/encoding/hex.js" ;
99import { parseTypedData } from "../../../../utils/signatures/helpers/parse-typed-data.js" ;
1010import type { Prettify } from "../../../../utils/type-utils.js" ;
1111import type {
@@ -141,39 +141,32 @@ export class EnclaveWallet implements IWebWallet {
141141 const transaction : Record < string , Hex | number | undefined > = {
142142 to : tx . to ? getAddress ( tx . to ) : undefined ,
143143 data : tx . data ,
144- value : typeof tx . value === "bigint" ? toHex ( tx . value ) : undefined ,
145- gas :
146- typeof tx . gas === "bigint"
147- ? toHex ( tx . gas + tx . gas / BigInt ( 10 ) )
148- : undefined , // Add a 10% buffer to gas
144+ value : hexlify ( tx . value ) ,
145+ gas : hexlify ( tx . gas ) ,
149146 nonce :
150- typeof tx . nonce === "number"
151- ? toHex ( tx . nonce )
152- : toHex (
153- await import (
154- "../../../../rpc/actions/eth_getTransactionCount.js"
155- ) . then ( ( { eth_getTransactionCount } ) =>
156- eth_getTransactionCount ( rpcRequest , {
157- address : getAddress ( this . address ) ,
158- blockTag : "pending" ,
159- } ) ,
160- ) ,
161- ) ,
147+ hexlify ( tx . nonce ) ||
148+ toHex (
149+ await import (
150+ "../../../../rpc/actions/eth_getTransactionCount.js"
151+ ) . then ( ( { eth_getTransactionCount } ) =>
152+ eth_getTransactionCount ( rpcRequest , {
153+ address : getAddress ( this . address ) ,
154+ blockTag : "pending" ,
155+ } ) ,
156+ ) ,
157+ ) ,
162158 chainId : toHex ( tx . chainId ) ,
163159 } ;
164160
165- if ( typeof tx . maxFeePerGas === "bigint" ) {
166- transaction . maxFeePerGas = toHex ( tx . maxFeePerGas ) ;
167- transaction . maxPriorityFeePerGas =
168- typeof tx . maxPriorityFeePerGas === "bigint"
169- ? toHex ( tx . maxPriorityFeePerGas )
170- : undefined ;
161+ if ( hexlify ( tx . maxFeePerGas ) ) {
162+ transaction . maxFeePerGas = hexlify ( tx . maxFeePerGas ) ;
163+ transaction . maxPriorityFeePerGas = hexlify ( tx . maxPriorityFeePerGas ) ;
171164 transaction . type = 2 ;
172165 } else {
173- transaction . gasPrice =
174- typeof tx . gasPrice === "bigint" ? toHex ( tx . gasPrice ) : undefined ;
166+ transaction . gasPrice = hexlify ( tx . gasPrice ) ;
175167 transaction . type = 0 ;
176168 }
169+
177170 return signEnclaveTransaction ( {
178171 client,
179172 storage,
@@ -253,3 +246,7 @@ export class EnclaveWallet implements IWebWallet {
253246 } ;
254247 }
255248}
249+
250+ function hexlify ( value : string | number | bigint | undefined ) {
251+ return value === undefined || isHex ( value ) ? value : toHex ( value ) ;
252+ }
0 commit comments