0

I have tried some methods but its not working, and dint got any working example on internet.

struct customerId{
        address id;
        mapping(string=>uint) customerAmount;
        mapping(string=>uint) customerPayed; 
        bytes customer_address;
    }
function add() public { 
cosId memory a= cosId({
            id:msg.sender,
            cosAmount:123,
            cosPayed:123,
            customer_address:"abcd"
        });
}

1 Answer 1

1

If you're using a mapping that store customerId struct, you can see this smart contract example:

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

contract Test {

    struct customerId{
        address id;
        mapping(string=>uint) customerAmount;
        mapping(string=>uint) customerPayed; 
        bytes customer_address;
    }

    mapping(address=>customerId) _arrayCustomerId;

    function add() public {
        customerId storage customer = _arrayCustomerId[msg.sender];
        customer.id = address(msg.sender);
        customer.customerAmount["test"] = 1;
        customer.customerPayed["test1"] = 2;
        customer.customer_address = abi.encodePacked(msg.sender);
    }

    function getElement() external view returns(address, uint, uint, bytes memory){
        return (_arrayCustomerId[msg.sender].id, _arrayCustomerId[msg.sender].customerAmount["test"], _arrayCustomerId[msg.sender].customerPayed["test1"], _arrayCustomerId[msg.sender].customer_address);
    }

}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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