-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Decoding array of struct (MyStruct[]) to an array of objects? #3591
Comments
Using this as a workaround: const entryProps = exchangeAbi
.find((abi) => abi.name === "entriesArray")
.outputs[0].components.map((c) => c.name);
const decodeEntriesArray = (entries) => {
// workaround: https://github.com/ethereum/web3.js/issues/3591
return entries.map((entry) => {
return Object.fromEntries(
entry.map((val, idx) => {
return [entryProps[idx], val];
})
);
});
}; |
Sorry for the delay, this is a pretty great idea! Drastically improves the UX. This would definitely be a breaking change in the way existing applications use web3.js, but an alternative option would be to include the above helpers, until a breaking change is ready. We could create a method (eg: Thoughts: @cgewecke @kevholder |
Agree, a really good improvement. There's also precedent at Web3 for gating some enhancements like this behind a settings flag. For example revert reason fetching is currently enabled by setting |
Great idea. We can probably push this up the list |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment. |
Would you like me to send a pull request? |
That would be great! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment. |
@GregTheGreek Any update on this issue? Were the helper functions mentioned in the discussion above implemented? Also, I think the issue should be reopened and not marked stale. |
is there any inbuilt method in web3 for achieving this ? |
Hi @GregTheGreek. Any updates on this issue? |
Expected behavior
When a method returns an array of structs (e.g.
MyStruct[]
), web3js should decode it to an array of objects that have the same shape as MyStruct.Actual behavior
When a method returns an array of structs (e.g.
MyStruct[]
), web3js decodes it as an array of arrays.Steps to reproduce the behavior
Environment
The text was updated successfully, but these errors were encountered: