I am very new to Solidity and Javascript developments and I have faced some issues lately.
Use case:
- Store an array of data from Javascript to Solidity.
- Return the stored array from Solidity back to Javascript code.
Javascript code for getting the array:
async loadBlockchain() {
const web3 = window.web3
const accounts = await web3.eth.getAccounts()
console.log("Eth account: " + accounts)
this.setState({account: accounts[0]})
const networkID = await web3.eth.net.getId()
console.log("Eth network ID: " + networkID)
const networkData = storeHash.networks[networkID]
if(networkData) {
//Fetch the smart contract from the address
const abi = storeHash.abi
const address = networkData.address
const contract = new web3.eth.Contract(abi, address)
this.setState({ contract })
console.log(contract)
var fileHashList = await contract.methods.get().call()
console.log(fileHashList)
}
else
{
window.alert('Smart contract not deployed to detected network')
}
}
Solidity code for returning the array:
pragma solidity 0.5.16;
pragma experimental ABIEncoderV2;
contract storeHash {
//Upload stored file hash in blockchain
string[] public fileHash;
//uint256 public fileCount = 0;
//Store hash value
function set(string memory _fileHash) public {
fileHash.push(_fileHash);
}
//Retrieve hash value
function get() public view returns (string[] memory) {
return fileHash;
}
Issue:
The array returned seems to be read as bigNumber and showing the following error:
Unhandled Rejection (null): overflow (fault="overflow", operation="toNumber", value="36830543755683898667443985212771609229556685323236234700674529361303541601398", code=NUMERIC_FAULT, version=bignumber/5.3.0)
The error message in console:
Uncaught (in promise) null: overflow (fault="overflow", operation="toNumber", value="36830543755683898667443985212771609229556685323236234700674529361303541601398", code=NUMERIC_FAULT, version=bignumber/5.3.0)
at Logger.makeError (http://localhost:3000/static/js/vendors~main.chunk.js:6622:19)
at Logger.throwError (http://localhost:3000/static/js/vendors~main.chunk.js:6633:18)
at throwFault (http://localhost:3000/static/js/vendors~main.chunk.js:3782:17)
at BigNumber.toNumber (http://localhost:3000/static/js/vendors~main.chunk.js:3584:9)
at http://localhost:3000/static/js/vendors~main.chunk.js:666:54
at Array.forEach (<anonymous>)
at unpack (http://localhost:3000/static/js/vendors~main.chunk.js:661:10)
at ArrayCoder.decode (http://localhost:3000/static/js/vendors~main.chunk.js:818:39)
at http://localhost:3000/static/js/vendors~main.chunk.js:669:23
at Array.forEach (<anonymous>)
at unpack (http://localhost:3000/static/js/vendors~main.chunk.js:661:10)
at TupleCoder.decode (http://localhost:3000/static/js/vendors~main.chunk.js:1275:92)
at AbiCoder.decode (http://localhost:3000/static/js/vendors~main.chunk.js:185:20)
at ABICoder.push../node_modules/web3-eth-abi/lib/index.js.ABICoder.decodeParametersWith (http://localhost:3000/static/js/vendors~main.chunk.js:308757:28)
at ABICoder.push../node_modules/web3-eth-abi/lib/index.js.ABICoder.decodeParameters (http://localhost:3000/static/js/vendors~main.chunk.js:308739:15)
at Contract.push../node_modules/web3-eth-contract/lib/index.js.Contract._decodeMethodReturn (http://localhost:3000/static/js/vendors~main.chunk.js:310221:20)
at Method.outputFormatter (http://localhost:3000/static/js/vendors~main.chunk.js:310556:32)
at Method.push../node_modules/web3-core-method/lib/index.js.Method.formatOutput (http://localhost:3000/static/js/vendors~main.chunk.js:306298:50)
at sendTxCallback (http://localhost:3000/static/js/vendors~main.chunk.js:306848:25)
at cb (http://localhost:3000/static/js/vendors~main.chunk.js:198169:22)
at Item.push../node_modules/process/browser.js.Item.run (http://localhost:3000/static/js/vendors~main.chunk.js:242191:12)
at drainQueue (http://localhost:3000/static/js/vendors~main.chunk.js:242155:34)
May I know how can I fix this issue and get the array I wanted in my NodeJs application? Thank you in advance!