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

Add contract.decodeMethodData(...) method to decode contract methods and to contract.deploy(...).decodeData(...) decode constructor parameters #6950

Merged
merged 11 commits into from
Apr 7, 2024
1 change: 1 addition & 0 deletions packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@
}),

encodeABI: () => encodeMethodABI(methodAbi, abiParams),
decodeABI: (data?: string) => decodeMethodReturn(methodAbi, data),

Check warning on line 1164 in packages/web3-eth-contract/src/contract.ts

View check run for this annotation

Codecov / codecov/patch

packages/web3-eth-contract/src/contract.ts#L1164

Added line #L1164 was not covered by tests

createAccessList: async (
options?: PayableCallOptions | NonPayableCallOptions,
Expand Down
16 changes: 16 additions & 0 deletions packages/web3-eth-contract/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ export interface NonPayableMethodObject<Inputs = unknown[], Outputs = unknown[]>
*/
encodeABI(): string;

/**
* Decode raw result of method call into readable value(s).
*
* @param data - The data to decode.
* @returns - The decoded data.
*/
decodeABI<SpecialOutput = Outputs>(data?: string): SpecialOutput;

/**
* This method generates an access list for a transaction. You must specify a `from` address and `gas` if it’s not specified in options.
*
Expand Down Expand Up @@ -400,6 +408,14 @@ export interface PayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
*/
encodeABI(): HexString;

/**
* Decode raw result of method call into readable value(s).
*
* @param data - The data to decode.
* @returns - The decoded data.
*/
decodeABI<SpecialOutput = Outputs>(data?: HexString): SpecialOutput;

/**
* This method generates an access list for a transaction. You must specify a `from` address and `gas` if it’s not specified in options.
*
Expand Down
Loading