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. Create a function in solidity with the function keyword to perform a specific task. The following example demonstrates how we can create a simple function:
contract Test {    function functionName() {        // Do something    }}
  1. Create another function to accept input parameters. These parameters can be declared just like variables. The following example accepts two parameters of type uint:

contract Test {    function add(uint _a, uint _b) public {        // Do something    }}
  1. Define output parameters with the same syntax. The returns keyword is used to specify the return. The following function returns a variable of type uint:
contract Test {    function add(uint _a, uint _b) public pure        returns (uint sum)    {        sum = _a + _b;    }   }
  1. Declare return ...
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