0

I would like to create a balance for each "vault". for example i will have my struct:

struct unnamed {
    string[] crowdFundName;   
}

I would like to add a balance to each vault for example crowdFundName[test] balance is x, crowdFundName[test2] is y.

1 Answer 1

0

You can use nested mapping inside your struct for mapping different balances in it. You can see this example:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Test {

    struct unnamed {
        mapping(string=>uint) crowdFundName;   
    }

    mapping(address=>unnamed) _map;

    // Add crowdFund
    function addCrowdfund(string memory _nameDeposit, uint _amount) public {
        _map[msg.sender].crowdFundName[_nameDeposit] = _amount;
    }

    // Get specific crowdFund
    function retrieveCrowdfund(string memory _nameDeposit) external view returns(uint) {
        return _map[msg.sender].crowdFundName[_nameDeposit];
    }

}
2
  • Appreciate it and how do i link funds to diffrent crowdFunds ? Commented Apr 25, 2022 at 16:55
  • Instead 'msg.sender' that I put into two functions, you can add another input parameter with datatype 'address' and you'll replace msg.sender with it Commented Apr 25, 2022 at 17:01

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.