Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit ed1460c

Browse files
author
Alex
authored
Add abiitem (#6778)
* add abiitem * update * update contract * update changelog * update abi to fixture
1 parent a6b685e commit ed1460c

File tree

6 files changed

+128
-12
lines changed

6 files changed

+128
-12
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
anonymous: false,
3+
constant: true,
4+
inputs: [
5+
{
6+
name: 'testMe',
7+
type: 'uint256[3]'
8+
},
9+
{
10+
name: 'inputA',
11+
type: 'tuple',
12+
components: [
13+
{
14+
name: 'a',
15+
type: 'uint8'
16+
},
17+
{
18+
name: 'b',
19+
type: 'uint8'
20+
}
21+
]
22+
},
23+
{
24+
name: 'inputB',
25+
type: 'tuple[]',
26+
components: [
27+
{
28+
name: 'a1',
29+
type: 'uint256'
30+
},
31+
{
32+
name: 'a2',
33+
type: 'uint256'
34+
}
35+
]
36+
},
37+
{
38+
name: 'inputC',
39+
type: 'uint8',
40+
indexed: false
41+
}
42+
],
43+
name: "testName",
44+
outputs: [
45+
{
46+
name: "test",
47+
type: "uint256"
48+
},
49+
{
50+
name: 'outputA',
51+
type: 'tuple',
52+
components: [
53+
{
54+
name: 'a',
55+
type: 'uint8'
56+
},
57+
{
58+
name: 'b',
59+
type: 'uint8'
60+
}
61+
]
62+
},
63+
{
64+
name: 'outputB',
65+
type: 'tuple[]',
66+
components: [
67+
{
68+
name: 'a1',
69+
type: 'uint256'
70+
},
71+
{
72+
name: 'a2',
73+
type: 'uint256'
74+
}
75+
]
76+
}
77+
],
78+
payable: false,
79+
stateMutability: "pure",
80+
type: "function",
81+
gas: 175875
82+
}

packages/web3-eth-contract/test/unit/contract.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { ValidChains, Hardfork, AccessListResult, Address, ETH_DATA_FORMAT , DEF
2020
import { Web3ContractError } from 'web3-errors';
2121
import { Web3Context , Web3ConfigEvent } from 'web3-core';
2222
import { Web3ValidatorError } from 'web3-validator';
23-
23+
import { AbiItem } from 'web3-utils';
24+
import {Abi} from '../fixtures/Abi.json'
2425
import { Contract } from '../../src';
2526
import { sampleStorageContractABI } from '../fixtures/storage';
2627
import { GreeterAbi, GreeterBytecode } from '../shared_fixtures/build/Greeter';
@@ -110,6 +111,16 @@ describe('Contract', () => {
110111
expect(contract).toBeInstanceOf(Contract);
111112
});
112113

114+
it('should init with abiItem, options and context', () => {
115+
const contract = new Contract(
116+
[Abi as AbiItem],
117+
{ gas: '123' },
118+
{ config: { defaultAccount: '0x00000000219ab540356cBB839Cbe05303d7705Fa' } },
119+
);
120+
121+
expect(contract).toBeInstanceOf(Contract);
122+
});
123+
113124
it('should init with abi, address and options', () => {
114125
const contract = new Contract([], '0x00000000219ab540356cBB839Cbe05303d7705Fa', {
115126
gas: '123',

packages/web3-types/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,8 @@ Documentation:
177177
- Interface `MetaMaskProvider` added and is part of `SupportedProviders` (#6534)
178178
- `gasPrice` was added to `Transaction1559UnsignedAPI` type. (#6539)
179179

180-
## [Unreleased]
180+
## [Unreleased]
181+
182+
### Added
183+
184+
- Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678)

packages/web3-types/src/eth_abi_types.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,6 @@ export type AbiErrorFragment = AbiBaseFragment & {
139139
readonly inputs?: ReadonlyArray<AbiParameter>;
140140
};
141141

142-
// https://docs.soliditylang.org/en/latest/abi-spec.html#json
143-
export type AbiFragment =
144-
| AbiConstructorFragment
145-
| AbiFunctionFragment
146-
| AbiEventFragment
147-
| AbiErrorFragment
148-
| AbiFallbackFragment;
149-
150-
export type ContractAbi = ReadonlyArray<AbiFragment>;
151142

152143
export type AbiInput =
153144
| string
@@ -161,6 +152,28 @@ export type AbiInput =
161152
}
162153
| { readonly [key: string]: unknown };
163154

155+
export interface AbiOutput {
156+
name: string;
157+
type: string;
158+
components?: AbiOutput[];
159+
internalType?: string;
160+
}
161+
162+
163+
164+
// https://docs.soliditylang.org/en/latest/abi-spec.html#json
165+
export type AbiFragment =
166+
| AbiConstructorFragment
167+
| AbiFunctionFragment
168+
| AbiEventFragment
169+
| AbiErrorFragment
170+
| AbiFallbackFragment
171+
172+
// to be compatible with web3js v1
173+
export type AbiItem = AbiFragment
174+
export type ContractAbi = ReadonlyArray<AbiFragment> | ReadonlyArray<AbiItem>
175+
176+
164177
// https://docs.soliditylang.org/en/develop/abi-spec.html#json
165178
export type JsonFunctionInterface = {
166179
type: 'function';

packages/web3-utils/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,8 @@ Documentation:
187187

188188
- Fixed an issue with detecting Uint8Array (#6486)
189189

190-
## [Unreleased]
190+
## [Unreleased]
191+
192+
### Added
193+
194+
- Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678)

packages/web3-utils/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ export * from './uuid.js';
3232
export * from './web3_eip1193_provider.js';
3333
export * from './socket_provider.js';
3434
export * from './uint8array.js';
35+
// for backwards compatibility with v1
36+
export {AbiItem} from 'web3-types';

0 commit comments

Comments
 (0)