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[]"
}

1 Answer 1

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"
}

1
  • i tried it, however it is throwing error: call revert exception [ See: 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 at 13:22

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

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