Address book is nothing but a large mapping of your contacts where you can assign a real identities to the blockchain addresses you often interact with.
Every address book entry fetched or created using the address book contains the following data:
{ // address book entry model
id: '<unique id of the address book entry>',
alias: '<alias assigned to the address book entry>',
address: '<blockchain address assigned to the entry>',
phone_number: '<phone number>',
email: '<email assigned to the address book entry>',
created_at: '<timestamp>'
}
Only authorized users can edit their address book entries.
Requests to manage and read the address book are shown below. Before running any of them, you have to obtain the User object connection. This is explained in the User Authentication section.
Creating new entry
// user object obtained
const newEntry = await user.addToAddressBook({
address: '0x4Ed918C7800F5dc34d2C774f6EA5fbd15f1a94a7',
alias: 'random-addr',
phone_number: '+123456789', // phone number is optional
email: 'john@doe.com' // email is optional
});
console.log(`entry created, id: ${newEntry.id}`);
Update existing entry
// user object obtained
const existingEntryId = '<address book entry id>';
const updatedEntry = await user.updateAddressBook({
id: existingEntryId,
address: "<new address | or old value>",
alias: "<new alias | or old value>",
phone_number: "<new phone number>", // phone number is optional
email: "<new email>" // email is optiona;l
});
Fetch entry by alias
// user object obtained
const entryAlias = '<existing alias in addressbook>';
const fetchedEntry = await user.getFromAddressBook(entryAlias);
Fetch all entries
// user object obtained
const allEntries = await user.getAllFromAddressBook();
// returns the list of all address book entries