Skip to content

Commit 78784c8

Browse files
ryanioholgerd77
authored andcommitted
allow eth_estimateGas to have optional to
1 parent 4416bfb commit 78784c8

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

packages/client/lib/rpc/modules/eth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { decode } from 'rlp'
1212
import { middleware, validators } from '../validation'
1313
import { INVALID_PARAMS } from '../error-code'
14-
import { RpcCallTx } from '../types'
14+
import { RpcTx } from '../types'
1515
import type { Chain } from '../../blockchain'
1616
import type { EthereumClient } from '../..'
1717
import type { EthereumService } from '../../service'
@@ -47,7 +47,7 @@ export class Eth {
4747
])
4848

4949
this.estimateGas = middleware(this.estimateGas.bind(this), 2, [
50-
[validators.transaction(['to'])],
50+
[validators.transaction()],
5151
[validators.blockOption],
5252
])
5353

@@ -114,7 +114,7 @@ export class Eth {
114114
* 2. integer block number, or the string "latest", "earliest" or "pending"
115115
* @returns The return value of the executed contract.
116116
*/
117-
async call(params: [RpcCallTx, string]) {
117+
async call(params: [RpcTx, string]) {
118118
const [transaction, blockOpt] = params
119119

120120
if (!this._vm) {
@@ -172,7 +172,7 @@ export class Eth {
172172
* 2. integer block number, or the string "latest", "earliest" or "pending"
173173
* @returns The amount of gas used.
174174
*/
175-
async estimateGas(params: [RpcCallTx, string]) {
175+
async estimateGas(params: [RpcTx, string]) {
176176
const [transaction, blockOpt] = params
177177

178178
if (!this._vm) {

packages/client/lib/rpc/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export interface RpcCallTx {
1+
export interface RpcTx {
22
from?: string
3-
to: string
3+
to?: string
44
gas?: string
55
gasPrice?: string
66
value?: string

packages/client/lib/rpc/validation.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,13 @@ export const validators = {
160160
},
161161

162162
/**
163-
* validator to ensure required transaction fields are present and checks for valid address and hex values.
164-
* @param params parameters of method
165-
* @param index index of parameter
163+
* validator to ensure required transaction fields are present, and checks for valid address and hex values.
164+
* @param requiredFields array of required fields
165+
* @returns validator function with params:
166+
* - @param params parameters of method
167+
* - @param index index of parameter
166168
*/
167-
transaction(requiredFields: string[]) {
169+
transaction(requiredFields: string[] = []) {
168170
return (params: any[], index: number) => {
169171
if (typeof params[index] !== 'object') {
170172
return {

0 commit comments

Comments
 (0)