#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# An address book as a contract

ArgentinaMember Posts: 19
Hi guys,
I was trying to create my first own contract but I run into something I'm not sure how to solve, if it's possible.
I'm trying to create an address book, e.g. store a name, phone number and date of birth for each ethereum address. But I realized that given that the storage is just a set of key/value pairs of up to 32 bytes I don't know how to associate more than one value to an address/key.
One of the craziest things that came up to my mind was that I'd need to create one contract for each of the value I wanted to associate.
How would you do this?
I'm feeling a bit dumb, to be honest, but I don't see the answer based on my current knowledge of ethereum.

Cheers!

• Member Posts: 188 ✭✭✭
edited July 2014
You can use multiple offsets to store the entire record:
contract.storage[key] = name
contract.storage[key+1] = phone
contract.storage[key+2] = date of birth
Depending on your choice of key (is it uses provided or not) you might want to do some additional range checking and modulo math to ensure that they don't overlap.
• ArgentinaMember Posts: 19
Yes, I thought about that mechanism but that seems to be unsafe since the key would be the ethereum address, so they can overlap (I guess it's very unlikely but it could happen).
• Member Posts: 188 ✭✭✭
In that case you can do something like this:
HASH = 2 ^ 160
address = msg.sender # if user supplied check that address < 2^160
key = HASH + address * 3
contract.storage[key] = name
contract.storage[key + 1] = phone
contract.storage[key + 2] = date of birth
• ArgentinaMember Posts: 19
Thanks mids106!