0

I see the following error:

TypeError: Type String Memory is not implicitly convertable to expected type adress while trying to execute

with the following code:

pragma solidity >=0.4.18 <0.5.13;

contract KYC {
   struct Customer { 
      string userName;
      string customerData;
      address Bank;
   }
   mapping (address => Customer) customers;
   address[] public customersArray;
   
 struct Bank { 
      string Name;
      address ethAddress;
      string regNumber;
   }
   mapping (address => Bank) bank;
   address[] public banksArray;
   
   
    function addCustomer (address _address, string memory _userName, string memory _customerData, address _bank) public {
        Customer storage customer = customers[_address];
        
        customer.userName=_userName;
        customer.customerData=_customerData;
        customer.Bank=_bank;
        
        customersArray.push(_address) -1;
    }
    
   function getCustomer(string memory uName) view public returns (string memory) {
        Customer storage customer = customers[uName];
        return customer.customerData;
    }
   
}

1 Answer 1

0

The error is in this line Customer storage customer = customers[uName]; Your customers mapping maps address to the Customer struct whereas you are trying to map a the string uName to the struct. There are different ways you can receive customer data.

  1. Get an address as a function parameter and return the name of the customer at this address.

  2. Use pragma experimental ABIEncoderV2 and return the struct based on the address.

    function getCustomer(address _address) view public returns (Customer memory) {
    
         return customers[_address]; 
    
    }
    

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.