Skip to Content
Ethereum Cookbook
book

Ethereum Cookbook

by Manoj P R
August 2018
Intermediate to advanced
404 pages
11h 19m
English
Packt Publishing
Content preview from Ethereum Cookbook

Mapping

Follow these steps to create mappings in solidity:

  1. Mappings are created with key-value pairs. A mapping can be compared with a hash table or dictionary. The following example creates a mapping of an address and a user-defined type, and another mapping with an address and an unsigned integer. These are used for storing employee data:
contract test {    struct Person {        uint id;        string name;    }        mapping(address => Person) employees;        mapping(address => uint) balances;        function insert(address _employee, uint _id,         string _name, uint _balance) public {        employees[_employee] = Person({            id: _id,            name: _name        });        balances[_employee] = _balance;    }}
  1. Mappings can be nested to create a more complex data structure:

contract test {     mapping(address ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building Ethereum Dapps

Building Ethereum Dapps

Roberto Infante
Ethereum For Dummies

Ethereum For Dummies

Michael G. Solomon

Publisher Resources

ISBN: 9781789133998Supplemental Content