Intro
@MoralisTeam, thanks for creating this boilerplate. Iām working on my first project as part of Chainlink hackathon, and your boilerplate has been most helpful.
Wanted to share an issue I ran into. Maybe it will help others, and wondering whatās the ārightā way to address the issue.
Details
I have a simple ERC1155 contract, and wanted to replace the MetaCoin example in boilerplate -> Contracts with my own. So I created an abi (using hardhat-abi-exporter), and then replicated most of what I saw in src/contracts/contractInfo.json
.
It mostly worked. However I noticed that functions with array inputs didnāt work. For example, the standard balanceOf(address, uint256)
worked, but balanceOfBatch(address[], uint256[])
suffered from 2 errors related to parameters that were arrays:
- The
uint256[]
was causing an āparam.map is not a function errorā
- The
address[]
was causing an invalid argugment error
I tracked this down to node_modules/web3-eth-abi/lib/index.js
the function is ABICoder.prototype.formatParam
, and observed that:
- The code has regex to identify integer arrays, and attempts to process them. But it assumes the param IS an array, and calls param.map. The form input from Contracts UI is not an array, itās a string. Here are code snippets:
// I'm snipping relevant code from ABICoder.prototype.formatParam
const paramTypeBytesArray = new RegExp(/^bytes([0-9]*)\[\]$/);
const paramTypeNumberArray = new RegExp(/^(u?int)([0-9]*)\[\]$/);
if (type.match(paramTypeBytesArray) || type.match(paramTypeNumberArray)) {
return param.map(p => this.formatParam(type.replace('[]', ''), p));
}
- The code had no awareness of
address[]
, and was treating these as a string. When the call is evenutally made to the Contract, I suspect this invalid argument is triggered.
End
I temporarily confirmed / got around this issue by making some changes to web3-eth-abi code. I know this isnāt the right solution. But it did allow me to confirm the issue, and I was able to successfully call my contract functions that needed array inputs.
Iām wondering if the Contract.jsx or some other ethereum-boilerplate code changes to better support arrays in Contracts UI. Apologies, Iām new to React as well, and so donāt have an informed comment on this. Still trying to wrap my head around everything.
Thanks again team, Iām really enjoying the Moralis features as I work on my hackathon project!