0

I creating dApp and I want to add some sort of registration pannel(add nickname to wallet address) and its nessesary to store this data on db (public wallet address, nickname, email(optionally)). So can I make a function which can add this feature?

1 Answer 1

1

If you have somewhat complex data that you expect to be used mostly every time I would suggest mapping address to an object.

Declare the object:

struct registration = {
    string nickname; 
    string email;
}

Then create the mapping:

mapping(address -> registration) database;

You can set the data by calling:

database[targetAddress].nickname = newNickname;
database[targetAddress].email = newEmail; // leave black to keep the initialization value ""

Or

database[targetAddress] = registration(newNickname, newEmail);
database[targetAddress] = registration(newNickname, ); // if you wanted to initialize to "" in this case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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