Skip to content

JsonRpcApiProvider: sendImmediate() #4819

Open
@adraffy

Description

@adraffy

Describe the Feature

Some RPCs cannot be batched. It would be nice to be able to force a send() to only contain one request instead of using batchMaxSize = 1 on the provider.


Maybe something like sendImmediate() (same arguments as send()) except just calls _send() directly and increases #nextId

This can be accomplished currently using _send() and constructing a JsonRpcPayload and handling the JsonRpcResult | JsonRpcError result but the #nextId doesn't get updated.

Code Example

await provider.sendImmediate('eth_getProof', ...)

// alternative idea #1
provider.nextId(); // expose the incrementer

// alternative idea #2:
await provider.flushDrain(); // clears timer and flushes payloads
await provider.send('eth_getProof', ...)
await provider.flushDrain(); // not guaranteed that payloads.length = 1

Possible implementation:

export async function sendImmediate(
  provider: ethers.JsonRpcApiProvider,
  method: string,
  params: any[]
): Promise<any> {
  const payload: ethers.JsonRpcPayload = {
    method,
    params,
    id: 1, // meh
    jsonrpc: '2.0',
  };
  return provider._send(payload).then(([res]) => {
    if ('result' in res) {
      return res.result;
    } else {
      throw provider.getRpcError(payload, res);
    }
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions