Skip to content

Commit 6001164

Browse files
Merge pull request #41 from jsertx/master
Fix finding the output types from abi definition
2 parents 80ae156 + 8f3a1e0 commit 6001164

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,64 @@ $ yarn add ethereum-multicall
4747
```
4848

4949
## Usage
50+
### Overloaded methods
51+
As the [official docs mentions here](https://docs.ethers.io/v3/api-contract.html#prototype):
5052

53+
> Due to signature overloading, multiple functions can have the same name. The first function specifed in the ABI will be bound to its name. To access overloaded functions, use the full typed signature of the functions (e.g. contract["foobar(address,uint256)"]).
54+
55+
So, when creating the contract call context, under the calls array property we should have that in mind and use the method signature rather than the method name. E.g.
56+
```js
57+
const contractCallContext: ContractCallContext = {
58+
reference: 'upV2Controller',
59+
contractAddress: '0x19891DdF6F393C02E484D7a942d4BF8C0dB1d001',
60+
abi: [
61+
{
62+
inputs: [],
63+
name: 'getVirtualPrice',
64+
outputs: [
65+
{
66+
internalType: 'uint256',
67+
name: '',
68+
type: 'uint256',
69+
},
70+
],
71+
stateMutability: 'view',
72+
type: 'function',
73+
},
74+
{
75+
inputs: [
76+
{
77+
internalType: 'uint256',
78+
name: 'sentValue',
79+
type: 'uint256',
80+
},
81+
],
82+
name: 'getVirtualPrice',
83+
outputs: [
84+
{
85+
internalType: 'uint256',
86+
name: '',
87+
type: 'uint256',
88+
},
89+
],
90+
stateMutability: 'view',
91+
type: 'function',
92+
},
93+
],
94+
calls: [
95+
{
96+
reference: 'getVirtualPriceWithInput',
97+
methodName: 'getVirtualPrice(uint256)',
98+
methodParameters: ['0xFFFFFFFFFFFFF'],
99+
},
100+
{
101+
reference: 'getVirtualPriceWithoutInput',
102+
methodName: 'getVirtualPrice()',
103+
methodParameters: [],
104+
},
105+
],
106+
};
107+
```
51108
### Import examples:
52109

53110
### JavaScript (ES3)

src/multicall.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,17 @@ export class Multicall {
331331
abi: AbiItem[],
332332
methodName: string
333333
): AbiOutput[] | undefined {
334+
const contract = new ethers.Contract(
335+
ethers.constants.AddressZero,
336+
abi as any
337+
);
338+
methodName = methodName.trim();
339+
if (contract.interface.functions[methodName]) {
340+
return contract.interface.functions[methodName].outputs;
341+
}
342+
334343
for (let i = 0; i < abi.length; i++) {
335-
if (abi[i].name?.trim() === methodName.trim()) {
344+
if (abi[i].name?.trim() === methodName) {
336345
return abi[i].outputs;
337346
}
338347
}

0 commit comments

Comments
 (0)