diff --git a/packages/web3-eth-contract/test/fixtures/Abi.json b/packages/web3-eth-contract/test/fixtures/Abi.json new file mode 100644 index 00000000000..3538463596d --- /dev/null +++ b/packages/web3-eth-contract/test/fixtures/Abi.json @@ -0,0 +1,82 @@ +{ + anonymous: false, + constant: true, + inputs: [ + { + name: 'testMe', + type: 'uint256[3]' + }, + { + name: 'inputA', + type: 'tuple', + components: [ + { + name: 'a', + type: 'uint8' + }, + { + name: 'b', + type: 'uint8' + } + ] + }, + { + name: 'inputB', + type: 'tuple[]', + components: [ + { + name: 'a1', + type: 'uint256' + }, + { + name: 'a2', + type: 'uint256' + } + ] + }, + { + name: 'inputC', + type: 'uint8', + indexed: false + } + ], + name: "testName", + outputs: [ + { + name: "test", + type: "uint256" + }, + { + name: 'outputA', + type: 'tuple', + components: [ + { + name: 'a', + type: 'uint8' + }, + { + name: 'b', + type: 'uint8' + } + ] + }, + { + name: 'outputB', + type: 'tuple[]', + components: [ + { + name: 'a1', + type: 'uint256' + }, + { + name: 'a2', + type: 'uint256' + } + ] + } + ], + payable: false, + stateMutability: "pure", + type: "function", + gas: 175875 +} \ No newline at end of file diff --git a/packages/web3-eth-contract/test/unit/contract.test.ts b/packages/web3-eth-contract/test/unit/contract.test.ts index e86d04cc4cd..b2917c86d9c 100644 --- a/packages/web3-eth-contract/test/unit/contract.test.ts +++ b/packages/web3-eth-contract/test/unit/contract.test.ts @@ -20,7 +20,8 @@ import { ValidChains, Hardfork, AccessListResult, Address, ETH_DATA_FORMAT , DEF import { Web3ContractError } from 'web3-errors'; import { Web3Context , Web3ConfigEvent } from 'web3-core'; import { Web3ValidatorError } from 'web3-validator'; - +import { AbiItem } from 'web3-utils'; +import {Abi} from '../fixtures/Abi.json' import { Contract } from '../../src'; import { sampleStorageContractABI } from '../fixtures/storage'; import { GreeterAbi, GreeterBytecode } from '../shared_fixtures/build/Greeter'; @@ -110,6 +111,16 @@ describe('Contract', () => { expect(contract).toBeInstanceOf(Contract); }); + it('should init with abiItem, options and context', () => { + const contract = new Contract( + [Abi as AbiItem], + { gas: '123' }, + { config: { defaultAccount: '0x00000000219ab540356cBB839Cbe05303d7705Fa' } }, + ); + + expect(contract).toBeInstanceOf(Contract); + }); + it('should init with abi, address and options', () => { const contract = new Contract([], '0x00000000219ab540356cBB839Cbe05303d7705Fa', { gas: '123', diff --git a/packages/web3-types/CHANGELOG.md b/packages/web3-types/CHANGELOG.md index 3b48f4ffc68..2dedcbca907 100644 --- a/packages/web3-types/CHANGELOG.md +++ b/packages/web3-types/CHANGELOG.md @@ -177,4 +177,8 @@ Documentation: - Interface `MetaMaskProvider` added and is part of `SupportedProviders` (#6534) - `gasPrice` was added to `Transaction1559UnsignedAPI` type. (#6539) -## [Unreleased] \ No newline at end of file +## [Unreleased] + +### Added + +- Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678) \ No newline at end of file diff --git a/packages/web3-types/src/eth_abi_types.ts b/packages/web3-types/src/eth_abi_types.ts index 0f461693602..07b9374f4db 100644 --- a/packages/web3-types/src/eth_abi_types.ts +++ b/packages/web3-types/src/eth_abi_types.ts @@ -139,15 +139,6 @@ export type AbiErrorFragment = AbiBaseFragment & { readonly inputs?: ReadonlyArray; }; -// https://docs.soliditylang.org/en/latest/abi-spec.html#json -export type AbiFragment = - | AbiConstructorFragment - | AbiFunctionFragment - | AbiEventFragment - | AbiErrorFragment - | AbiFallbackFragment; - -export type ContractAbi = ReadonlyArray; export type AbiInput = | string @@ -161,6 +152,28 @@ export type AbiInput = } | { readonly [key: string]: unknown }; + export interface AbiOutput { + name: string; + type: string; + components?: AbiOutput[]; + internalType?: string; + } + + + +// https://docs.soliditylang.org/en/latest/abi-spec.html#json +export type AbiFragment = + | AbiConstructorFragment + | AbiFunctionFragment + | AbiEventFragment + | AbiErrorFragment + | AbiFallbackFragment + +// to be compatible with web3js v1 +export type AbiItem = AbiFragment +export type ContractAbi = ReadonlyArray | ReadonlyArray + + // https://docs.soliditylang.org/en/develop/abi-spec.html#json export type JsonFunctionInterface = { type: 'function'; diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index d63c09119cc..1204a73951c 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -187,4 +187,8 @@ Documentation: - Fixed an issue with detecting Uint8Array (#6486) -## [Unreleased] \ No newline at end of file +## [Unreleased] + +### Added + +- Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678) \ No newline at end of file diff --git a/packages/web3-utils/src/index.ts b/packages/web3-utils/src/index.ts index 52bb219692b..e5f467ec5f8 100644 --- a/packages/web3-utils/src/index.ts +++ b/packages/web3-utils/src/index.ts @@ -32,3 +32,5 @@ export * from './uuid.js'; export * from './web3_eip1193_provider.js'; export * from './socket_provider.js'; export * from './uint8array.js'; +// for backwards compatibility with v1 +export {AbiItem} from 'web3-types'; \ No newline at end of file