TypeChain
TypeChain copied to clipboard
Truffle struct types are incorrect
Actual:
The generated types for calls to a solidity method that returns a struct make all integer fields be BN
.
However, this is not what Truffle currently does with structs. It leaves these values be returned as strings, so generated types are not usable in our project.
For example , the following code:
struct Struct {
uint256 a;
uint256 b;
}
function getStruct() external view returns (Struct memory);
will result in the following type declaration:
getStruct(
txDetails?: Truffle.TransactionDetails
): Promise<{
a: BN;
b: BN;
}>;
but it is trivial to see that event the Truffle console does not treat these values as 'BN':
truffle(development)> c.getStruct()
[
'150000',
'100000',
a: '150000',
b: '100000',
]
So the expected type declaration must be
getStruct(
txDetails?: Truffle.TransactionDetails
): Promise<{
a: string;
b: string;
}>;
In case this is to be viewed as an issue for the Truffle project itself also created an issue there: https://github.com/trufflesuite/truffle/issues/3914
Is this maybe related to the web3 issue discussed on this recent PR?
Is this maybe related to the web3 issue discussed on this recent PR?
A little, but the mentioned issue is about the types of accepted inputs within structs, and this issue is about types of outputs when a struct is returned, so the issues are not identical.
OK. I think we can wait for some response on trufflesuite/truffle#3914 -- if it's a bug in truffle, we can just wait for them to fix it and then bump minimum typechain's truffle version.
Until that happens, we can fix Typechain for the current Truffle version too -- PRs welcome :)