diff --git a/src/chain-adapters/EVM/EVM.ts b/src/chain-adapters/EVM/EVM.ts index e3717d0..2e41fac 100644 --- a/src/chain-adapters/EVM/EVM.ts +++ b/src/chain-adapters/EVM/EVM.ts @@ -18,7 +18,7 @@ import { concat, pad, isAddress, - SignedAuthorization, + type SignedAuthorization, } from 'viem' import { hashAuthorization } from 'viem/experimental' @@ -69,9 +69,11 @@ export class EVM extends ChainAdapter { const fees = await fetchEVMFeeProperties(this.client, transaction) - const nonce = await this.client.getTransactionCount({ - address: transaction.from, - }) + const nonce = + transaction.nonce ?? + (await this.client.getTransactionCount({ + address: transaction.from, + })) const { from, ...rest } = transaction @@ -87,12 +89,14 @@ export class EVM extends ChainAdapter { - const gasPrice = await this.client.getGasPrice() - const nonce = await this.client.getTransactionCount({ - address: transaction.from, - }) + const gasPrice = transaction.gasPrice ?? (await this.client.getGasPrice()) + const nonce = + transaction.nonce ?? + (await this.client.getTransactionCount({ + address: transaction.from, + })) - const { from, ...rest } = transaction; + const { from, ...rest } = transaction return { ...rest, @@ -105,8 +109,6 @@ export class EVM extends ChainAdapter { + extends Omit { from: Address + nonce?: number } // Legacy transaction request coming from your dApp (includes 'from' address) @@ -23,6 +24,8 @@ export interface EVMTransactionRequestLegacy { to: `0x${string}` value?: bigint gas?: bigint + gasPrice?: bigint + nonce?: number } // Legacy unsigned transaction to be signed diff --git a/src/chain-adapters/EVM/utils.ts b/src/chain-adapters/EVM/utils.ts index 644bf2f..abbd1b9 100644 --- a/src/chain-adapters/EVM/utils.ts +++ b/src/chain-adapters/EVM/utils.ts @@ -10,10 +10,18 @@ export async function fetchEVMFeeProperties( client: PublicClient, transaction: TransactionRequest ): Promise { - const [gas, feeData] = await Promise.all([ - client.estimateGas(transaction), - client.estimateFeesPerGas(), - ]) + const gasPromise = transaction.gas + ? Promise.resolve(transaction.gas) + : client.estimateGas(transaction) + const feeDataPromise = + transaction.maxFeePerGas && transaction.maxPriorityFeePerGas + ? Promise.resolve({ + maxFeePerGas: transaction.maxFeePerGas, + maxPriorityFeePerGas: transaction.maxPriorityFeePerGas, + }) + : client.estimateFeesPerGas() + + const [gas, feeData] = await Promise.all([gasPromise, feeDataPromise]) const maxFeePerGas = feeData.maxFeePerGas ?? BigInt(10_000_000_000) // 10 gwei const maxPriorityFeePerGas =