Welcome to Dev3
Search
K
📖

Address Book

Explains how to manage the address book.
Every Dev3 user gets his own address book space.
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:
1
{ // address book entry model
2
id: '<unique id of the address book entry>',
3
alias: '<alias assigned to the address book entry>',
4
address: '<blockchain address assigned to the entry>',
5
phone_number: '<phone number>',
6
email: '<email assigned to the address book entry>',
7
created_at: '<timestamp>'
8
}
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

1
// user object obtained
2
const newEntry = await user.addToAddressBook({
3
address: '0x4Ed918C7800F5dc34d2C774f6EA5fbd15f1a94a7',
4
alias: 'random-addr',
5
phone_number: '+123456789', // phone number is optional
6
email: '[email protected]' // email is optional
7
});
8
console.log(`entry created, id: ${newEntry.id}`);

Update existing entry

1
// user object obtained
2
const existingEntryId = '<address book entry id>';
3
const updatedEntry = await user.updateAddressBook({
4
id: existingEntryId,
5
address: "<new address | or old value>",
6
alias: "<new alias | or old value>",
7
phone_number: "<new phone number>", // phone number is optional
8
email: "<new email>" // email is optiona;l
9
});

Fetch entry by alias

1
// user object obtained
2
const entryAlias = '<existing alias in addressbook>';
3
const fetchedEntry = await user.getFromAddressBook(entryAlias);

Fetch all entries

1
// user object obtained
2
const allEntries = await user.getAllFromAddressBook();
3
// returns the list of all address book entries

Live example

Run this flow on a live coding environment here!