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 library in the same way a contract is defined, but with the library keyword:
libary libName {    //....}
  1. Consider the following differences while creating a library contract:

  • Libraries cannot have any state variables
  • Libraries cannot inherit nor be inherited
  • Libraries cannot have a fallback or payable functions to receive Ether
  1. Invoke the library functions like invoking external contract calls:
<library>.<function>();
  1. Calling a function in the library will use the delegatecall instruction. This allows the code to execute in the context of the caller:
library lib {    function getBal() returns (uint) {        return address(this).balance;    }}contract Sample {    function getBalance() returns (uint) { return lib.getBal(); ...
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