Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix having to cast web3.eth.Contract as unknown before casting to generated type #802

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dry-melons-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@typechain/web3-v1': minor
---

Edit Contract interface codegen to allow casting directly from web3-v1's base Contract types
2 changes: 1 addition & 1 deletion examples/web3-v1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const web3 = new Web3(RPC_HOST)
const fromWei = web3.utils.fromWei

const dai = new web3.eth.Contract(abi, DAI_ADDRESS) as any as Dai
const dai = new web3.eth.Contract(abi, DAI_ADDRESS) as Dai
const balance = await dai.methods.balanceOf('0x70b144972C5Ef6CB941A5379240B74239c418CD4').call()

console.log(`Our DAI balance is: ${fromWei(balance)}`)
Expand Down
1 change: 1 addition & 0 deletions packages/target-web3-v1-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"web3": "^1.6.0",
"web3-eth-contract": "^1.6.0",
"web3-core": "^1",
"web3-utils": "^1.6.0",
"@types/bn.js": "^4.11.6"
}
}
2 changes: 1 addition & 1 deletion packages/target-web3-v1-test/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface EventOptions {

export type Callback<T> = (error: Error, result: T) => void;
export interface ContractEventLog<T> extends EventLog {
returnValues: T;
returnValues: Partial<T>;
}
export interface ContractEventEmitter<T> extends EventEmitter {
on(event: "connected", listener: (subscriptionId: string) => void): this;
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.6.4/DataTypesInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface DataTypesInput extends BaseContract {
export interface DataTypesInputConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): DataTypesInput;
}

export interface DataTypesInput extends BaseContract {
clone(): DataTypesInput;
methods: {
input_address(input1: string): NonPayableTransactionObject<string>;
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.6.4/DataTypesPure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface DataTypesPure extends BaseContract {
export interface DataTypesPureConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): DataTypesPure;
}

export interface DataTypesPure extends BaseContract {
clone(): DataTypesPure;
methods: {
pure_address(): NonPayableTransactionObject<string>;
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.6.4/DataTypesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface DataTypesView extends BaseContract {
export interface DataTypesViewConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): DataTypesView;
}

export interface DataTypesView extends BaseContract {
clone(): DataTypesView;
methods: {
view_address(): NonPayableTransactionObject<string>;
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.6.4/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand Down Expand Up @@ -54,12 +55,15 @@ export type UpdateFrequencySet = ContractEventLog<{
1: string[];
}>;

export interface Events extends BaseContract {
export interface EventsConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): Events;
}

export interface Events extends BaseContract {
clone(): Events;
methods: {
emit_anon1(): NonPayableTransactionObject<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -26,12 +27,15 @@ export type Committed = ContractEventLog<{
0: string[];
}>;

export interface A extends BaseContract {
export interface AConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): A;
}

export interface A extends BaseContract {
clone(): A;
methods: {};
events: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -30,12 +31,15 @@ export type Committed_address_array = ContractEventLog<{
0: string[];
}>;

export interface B extends BaseContract {
export interface BConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): B;
}

export interface B extends BaseContract {
clone(): B;
methods: {};
events: {
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.6.4/Library/Lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface Lib extends BaseContract {
export interface LibConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): Lib;
}

export interface Lib extends BaseContract {
clone(): Lib;
methods: {
other(b: number | string | BN): NonPayableTransactionObject<string>;
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.6.4/LibraryConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface LibraryConsumer extends BaseContract {
export interface LibraryConsumerConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): LibraryConsumer;
}

export interface LibraryConsumer extends BaseContract {
clone(): LibraryConsumer;
methods: {
someOther(b: number | string | BN): NonPayableTransactionObject<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface NAME12mangling extends BaseContract {
export interface NAME12manglingConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): NAME12mangling;
}

export interface NAME12mangling extends BaseContract {
clone(): NAME12mangling;
methods: {
provider(): NonPayableTransactionObject<boolean>;
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.6.4/Overloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface Overloads extends BaseContract {
export interface OverloadsConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): Overloads;
}

export interface Overloads extends BaseContract {
clone(): Overloads;
methods: {
"overload1(int256)"(
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.6.4/Payable/Payable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface Payable extends BaseContract {
export interface PayableConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): Payable;
}

export interface Payable extends BaseContract {
clone(): Payable;
methods: {
non_payable_func(): NonPayableTransactionObject<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface PayableFactory extends BaseContract {
export interface PayableFactoryConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): PayableFactory;
}

export interface PayableFactory extends BaseContract {
clone(): PayableFactory;
methods: {
newPayable(): NonPayableTransactionObject<string>;
Expand Down
8 changes: 6 additions & 2 deletions packages/target-web3-v1-test/types/v0.8.9/ISimpleToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface ISimpleToken extends BaseContract {
export interface ISimpleTokenConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): ISimpleToken;
}

export interface ISimpleToken extends BaseContract {
clone(): ISimpleToken;
methods: {
transfer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { AbiItem } from "web3-utils";
import type { EventEmitter } from "events";
import type {
Callback,
Expand All @@ -21,12 +22,15 @@ export interface EventOptions {
topics?: string[];
}

export interface Issue552_Reproduction extends BaseContract {
export interface Issue552_ReproductionConstructor {
constructor(
jsonInterface: any[],
jsonInterface: AbiItem[],
address?: string,
options?: ContractOptions
): Issue552_Reproduction;
}

export interface Issue552_Reproduction extends BaseContract {
clone(): Issue552_Reproduction;
methods: {
bars(
Expand Down