Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ Released with 1.0.0-beta.37 code base.
### Added

- Introduce review and release guidelines. (#3460)
- Add EIP-1193 compatible provider to `AbstractProvider` interface. (#3499)
- Add Typescript definitions for contract `methods` and `call`. (#3454)

### Changed

- Change CI provider from Travis to Github Actions. (#3468)
- Update `web3-eth-abi` ABICoder dependency. (#3490)
- Improve code clarity of HttpProvider keepAlive option setting. (#3463)
- Updated type definitions for Web3 HTTP Provider. (#3482)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "web3-core",
"version": "1.2.7",
"description": "Web3 core tools for sub packages. This is an internal package.",
"description": "Web3 core tools for sub-packages. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core",
"license": "LGPL-3.0",
"engines": {
Expand Down
10 changes: 8 additions & 2 deletions packages/web3-core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

import * as net from 'net';
import { EventEmitter } from "events"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

import {
HttpProviderBase,
HttpProviderOptions,
Expand Down Expand Up @@ -411,9 +410,16 @@ export interface LogsOptions {

export type BlockNumber = string | number | BN | BigNumber | 'latest' | 'pending' | 'earliest' | 'genesis';

export interface RequestArguments {
method: string;
params?: any;
[key: string]: any;
}

export interface AbstractProvider {
send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void;
sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void;
send?(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void;
request?(args: RequestArguments): Promise<any>;
}

export type provider =
Expand Down
25 changes: 20 additions & 5 deletions packages/web3/types/tests/web3-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

import Web3 from 'web3';
import * as net from 'net';
import { AbstractProvider } from 'web3-core';
import { JsonRpcPayload, JsonRpcResponse } from "web3-core-helpers"
import { EventEmitter } from 'events';
import { AbstractProvider, RequestArguments } from 'web3-core';
import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers';

// $ExpectType Utils
Web3.utils;
Expand Down Expand Up @@ -89,9 +88,25 @@ web3 = new Web3('https://localhost:5000/', netSocket);
// $ExpectType Web3
web3 = new Web3();

class CustomProvider implements AbstractProvider {
class CustomProvider1 implements AbstractProvider {
sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {}
}

// $ExpectType Web3
web3 = new Web3(new CustomProvider1());

class CustomProvider2 implements AbstractProvider {
send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {}
sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {}
}

// $ExpectType Web3
web3 = new Web3(new CustomProvider2());

class CustomProvider3 implements AbstractProvider {
async request(args: RequestArguments) {}
sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {}
}

// $ExpectType Web3
web3 = new Web3(new CustomProvider());
web3 = new Web3(new CustomProvider3());