0

How can I add function and array to already deployed contract on the main net.

//Already deployed contract
struct User  {
      
    address  wallet_address;  
    string  userId;
    string  first_name;
    string  last_name;
    string  email_id;
    bool set;
    string private_key;

  }
 

  mapping(address => User)  users; 
  mapping(string => address) walletAccount;
  mapping(address => uint) public balanceOf;
  
  
  
  User public newUser ;
 
  uint public length;
  address public owner;
  
  
  constructor() public{
      
      owner = msg.sender;
  }
  
 

 

  function createNewUser(address userAcc,string memory _id,string memory firstName,string memory lastName,string memory emailId,string memory _private_key) public  {


      
     
      
      User storage user = users[userAcc];
      
      
     
     users[userAcc] = User(userAcc,_id,firstName,lastName,emailId,true,_private_key); 
      
      walletAccount[emailId] = userAcc;
      
       registeredArray.push(userAcc);
     
  }


 
  
 
  
  function getUser(address _userAddress,string memory _emailId) public view returns(address,string memory,string memory,string memory,string memory,string memory){
      
       User memory user = users[_userAddress];
       
       
      
        
       return(users[_userAddress].wallet_address,users[_userAddress].userId,users[_userAddress].first_name,users[_userAddress].last_name,users[_userAddress].email_id,users[_userAddress].private_key);
         
  }

How do I add this array to the struct of the deployed contract and also this new function to it?

  //Need to add to the deployed contract
  User[] public registeredArray;
  function Listofuser()public view returns(address[] memory){
    registeredArray.push(userAcc);
    return registeredArray;
  }

1 Answer 1

2

You can't modify already deployed contracts. They are immutable, so their contents can't be changed - only their internal state may be altered (so you can change a variable's value, for example).

If you need to make changes to an already deployed contract, you make the changes and deploy a new version to a new address.

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.