I try to get a loop run through all structs associated with the caller address, but I can't get my head around this warning. I think I understand the problem, but can't get my head around what should I do differently to achieve this result the other way.
The error I am getting:
TypeError: Integer constant expected.
--> minitest.sol:30:31:
|
30 | balance += Wallet[walletNumbers[msg.sender][i]].balance;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
My code simplified just for the error part:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^ 0.8 .0;
contract MiniTest {
uint nextWalletNumber = 0;
struct Wallet {
address owner;
uint balance;
uint debt;
}
Wallet[] public walletInfo;
mapping(address => uint[]) public walletNumbers;
function createWallet() public {
Wallet memory newWallet = Wallet(msg.sender, 1000, 0);
walletInfo.push(newWallet);
walletNumbers[msg.sender].push(nextWalletNumber);
nextWalletNumber++;
}
function allWalletsBalance() public view returns(uint) {
uint balance;
for (uint i; i < walletNumbers[msg.sender].length; i++) {
balance += Wallet[walletNumbers[msg.sender][i]].balance;
}
return balance;
}
}
Is there another way to achieve this for loop and take out uint from all structs associated with that address?
web3means decentralized web. so anything related to smartcontract or blockchain should be related to web3. Or what I am missing?