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

Arrays

Follow these steps to create arrays in solidity and to perform read/write operations:

  1. Arrays can be created with a fixed or dynamic length. Arrays can also hold user-defined types:
uint[10] numbers;struct Person {    uint id;    string name;}Person[] candidates;
  1. The creation of multidimensional arrays is supported by solidity:
// array of 3 dynamic arrays of boolbool[][3] table;

Note that the index value is reversed when compared with other languages. For example, to access the first element in the third array, you use a[2][0]:

  1. Arrays have a length parameter to store the number of elements in the array. Changing the length parameter of dynamic storage arrays can resize the arrays:
contract test {    address[] contributors; function donate() ...
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