I have a local testnet node using Hardhat. I can successfully deploy and test against my contract using plain javascript, async await
and const { ethers, upgrades } = require("hardhat");
.
I am correctly returning, and printing to the console, a BigNumber array with 2 elements from a contract function.
But the useDapp function call returns a different value.
I have tried everything: JSON.stringify(array)
returns [[]]
, array[0]
returns undefined, BigNumber.from(array).toNumber
throws some crazy BigNumber
error, etc. But I know the contract is giving it the correct values.
Why am I getting 2 different values in 2 different javascript files? I'm assuming it's an issue with the way the hardhat test file is retrieving the values vs. useDapp.
My useDapp front end hook looks like this which returns [Array(0)]
with length: 1
:
export function useGetArray(): BigNumber[] | undefined {
const {value,error}: any = useCall({
contract: new Contract(myContract, myInterface),
method: "getArray",
args: [],
}) ?? [];
if(error) {
return error;
} else {
return value;
};
}
My hardhat javascript test looks like this which returns [ BigNumber { value: "50" }, BigNumber { value: "129" } ]
:
CONTRACT = await ethers.getContractFactory("CONTRACT");
const contract = await CONTRACT.attach("0x109d198fca64d33Bd9F33E60333A544412cfAC7D");
array = await contract.getArray();
console.log(array);
Please know that 2 other nearly identical function calls using useDapp, and one even passing data to contract, work completely fine. So the issue does not lay in the address being used or imported ABI.