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

How to do it...

  1. Loops can be very tricky when it comes to solidty. There are two very common mistakes that anyone can easily overlook while writing smart contracts.
  2. Create a function that uses a for loop to iterate through an array of addresses and transfer the payout:
pragma solidity ^0.4.24;contract Payout {    // Arbitrary length array to store addresses    address[] private addresses;        // Mapping to store payout value    mapping (address => uint) public payouts;        // Function to transfer payouts    function payoutAll() public {        for(uint8 i = 0; i < addresses.length; i++) {            require(addresses[i].send(payouts[addresses[i]]));        }    }}
  1. The contract contains two potential bugs, which will arise when the length of the array exceeds a certain limit.
  2. For example, ...
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