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. To write the assembly inline, use the assembly keyword:
assembly {    // assembly code}
  1. Create local variables in the assembly by using the let keyword. For variables without any assignment, the default value will be assigned:
let xlet y := 2
  1. Access the variables that are defined outside the assembly directly:
function f(uint x) public {    assembly {        x := sub(x, 1)    }}
Assigning values to variables that point to memory or storage work differently inside solidity assembly. The assignment will only change the pointer and not the data.
  1. Create a for loop in the assembly just like a regular loop:
assembly {    for { let i := 0 } lt(i, 10) { i := add(i, 1) } {         y := add(y, 1)    }}
  1. Use the if statement to validate conditions inside ...
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