This question looks silly but it drives me crazy because I cant find a solution. I will make it clear below.

I use useDApp framework and with useCall hook. I can get correctly values returned from Solidity functions and everything works very perfectly. But wrong with these 2 functions:

function showRemainingDate(uint _id) public view returns(uint) {
    for (uint i = 0; i < users[msg.sender].numberOfCards; i++) {
        if (users[msg.sender].purchase[i].card.id == cards[_id].id) {
            return 30*86400 - (block.timestamp - users[msg.sender].purchase[i].purchaseDate);
    return 0;

function checkPurchase(uint _id) public view returns (bool) {
    for (uint i = 0; i < users[msg.sender].numberOfCards; i++) {
        if (users[msg.sender].purchase[i].card.id == cards[_id].id) {
            return true;
    return false;

After having deployed on Remix, I imported its address and ABI for my dApp project then used useCall hook like this:

export function useCheckPurchase(index) {
  const { value: checkPurchase } = useCall({
    contract: contract,
    method: "checkPurchase",
    args: [index],
  }) ?? {};
  return checkPurchase;

export function useShowRemainingDate(index) {
  const { value: showRemainingDate } = useCall({
    contract: contract,
    method: "showRemainingDate",
    args: [index],
  }) ?? {};
  return showRemainingDate;

The weird points start here, if I use purchaseCard hook/function (no matter on JS or Remix) and then console.log the values (just for example):


It would always return false and 0 for all parameter:

values appearing on console

While the values would always return correctly on Remix:

checkPurchase showRemainingDate

This is a very weird bug, Im sure there arent any typo in the names.

This is the contract address 0x29588f4714223bd492ce6500D6CEE0eCD4f1c51e in my examples and this is my Solidity code.

Thank you everyone, any answer from you guys are all appreciated.

  • Did you use the same wallet to connect remix and call functions in js? Commented Aug 29, 2022 at 19:42
  • @SteveGerrad of course yes, sir. everything works perfectly.
    – SnowyField
    Commented Aug 29, 2022 at 19:50

1 Answer 1


Okay, I finally know the reason.
After changing msg.sender into my wallet address on Solidity code, it worked perfectly.
From here, I can show that the problem is with msg.sender.

And this is the solution post, you guys can read more about it: https://stackoverflow.com/questions/72908375/solidity-function-returns-empty-array-on-ethersjs-hardhat-but-not-in-remix-ide

Hope this will help someone encountering my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.