3

I am Not able to get weeklyBusiness array inside User struct. as the contract is already deployed is there a way i can change ABI to get all components of User struct including arrays using userInfo function.

struct WeeklyBusiness {
   uint256 amount;
   uint256 time;
}

struct User {
   uint256 level;
   uint256 start;
   WeeklyBusiness[] weeklyBusiness;
   uint256[3] registered;
}

mapping(address => User) public userInfo;

Generated ABI:

{
      "inputs": [
        {
          "internalType": "address",
          "name": "",
          "type": "address"
        }
      ],
      "name": "userInfo",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "level",
          "type": "uint256"
        },
        {
          "internalType": "uint256",
          "name": "start",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function"
}

I tried add this in outputs of generated ABI, but it didn't worked:

{
      "internalType": "tuple[]",
      "name": "weeklyBusiness",
      "type": "tuple[]"
}
Suvi Negi
  • 31
  • 1

1 Answers1

0

you need to specify the correct tuple type for the array in the output of your ABI

{
  "inputs": [
    {
      "internalType": "address",
      "name": "",
      "type": "address"
    }
  ],
  "name": "userInfo",
  "outputs": [
    {
      "internalType": "uint256",
      "name": "level",
      "type": "uint256"
    },
    {
      "internalType": "uint256",
      "name": "start",
      "type": "uint256"
    },
    {
      "internalType": "tuple[]",
      "name": "weeklyBusiness",
      "type": "tuple[]",
      "components": [
        {
          "internalType": "uint256",
          "name": "amount",
          "type": "uint256"
        },
        {
          "internalType": "uint256",
          "name": "time",
          "type": "uint256"
        }
      ]
    },
    {
      "internalType": "uint256[3]",
      "name": "registered",
      "type": "uint256[3]"
    }
  ],
  "stateMutability": "view",
  "type": "function"
}

Rory
  • 437
  • 1
  • 13
  • i tried it, however it is throwing error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="userInfo(address)", data="0x00000000...............00000000", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0) – Suvi Negi Feb 19 '23 at 13:22