SlideShare a Scribd company logo
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
S O L I D I T Y
L I B R A R I E S
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
What is Library ?
A library is a different type of contract, that doesn't have any storage and cannot hold ether. This is
helpful when we want to re-use some piece of code.
This does not have payable and fallback function so libraries do not hold ether and do not have any
storage.
Library function deployed only at one specific address and these functions are called in context of
calling contract.
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
What is Library ?
pragma solidity ^ 0.4.20;
library math{
function add(uint _fValue, uint _sValue) public returns(uint){
return _fValue + _sValue;
}
}
contract salary{
function salarywithBouns(uint _salary, uint _bonus) public returns(uint){
return math.add(_salary,_bonus);
}
}
+ 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary  | www.tutorialsdiary.com
Using for Keyword
We can attach library function to any data type by using "using" and "for" keywords.
using A for B; pragma solidity ^ 0.4.20;
library math{
function add(uint _fValue, uint _sValue) public returns(uint){
return _fValue + _sValue;
}
}
contract salary{
using math for uint;
function salarywithBouns(uint _salary, uint _bonus) public
returns(uint){
return _salary.add(_bonus);
}
}

More Related Content

Similar to Solidity Tutorials- Libraries in solidity

Dot Net Accenture
Dot Net AccentureDot Net Accenture
Dot Net Accenture
Sri K
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
rashmita_mishra
 

Similar to Solidity Tutorials- Libraries in solidity (20)

Does your code spark joy? Refactoring techniques to make your life easier.
Does your code spark joy? Refactoring techniques to make your life easier.Does your code spark joy? Refactoring techniques to make your life easier.
Does your code spark joy? Refactoring techniques to make your life easier.
 
Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
 
Dot Net Accenture
Dot Net AccentureDot Net Accenture
Dot Net Accenture
 
Jumping-with-java8
Jumping-with-java8Jumping-with-java8
Jumping-with-java8
 
Prairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API ResponsesPrairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API Responses
 
Dictionary and sets-converted
Dictionary and sets-convertedDictionary and sets-converted
Dictionary and sets-converted
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
Go Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional ProgrammingGo Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional Programming
 
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScript
 
Dependency injection in CakePHP
Dependency injection in CakePHPDependency injection in CakePHP
Dependency injection in CakePHP
 
C questions
C questionsC questions
C questions
 
C#/.NET Little Pitfalls
C#/.NET Little PitfallsC#/.NET Little Pitfalls
C#/.NET Little Pitfalls
 
Good Coding Practices with JavaScript
Good Coding Practices with JavaScriptGood Coding Practices with JavaScript
Good Coding Practices with JavaScript
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)
 
10 things I’ve learnt In the clouds
10 things I’ve learnt In the clouds10 things I’ve learnt In the clouds
10 things I’ve learnt In the clouds
 

More from Tutorials Diary (11)

Solidity Tutorials- Difference between msg.sender and tx.origin
Solidity Tutorials- Difference between msg.sender and tx.originSolidity Tutorials- Difference between msg.sender and tx.origin
Solidity Tutorials- Difference between msg.sender and tx.origin
 
Solidity Tutorials- Transer/Send ether- Transfer(), send(), call() function i...
Solidity Tutorials- Transer/Send ether- Transfer(), send(), call() function i...Solidity Tutorials- Transer/Send ether- Transfer(), send(), call() function i...
Solidity Tutorials- Transer/Send ether- Transfer(), send(), call() function i...
 
Solidity Tutorials- Function call in solidity
Solidity Tutorials- Function call in soliditySolidity Tutorials- Function call in solidity
Solidity Tutorials- Function call in solidity
 
Constructor in solidity
Constructor in solidityConstructor in solidity
Constructor in solidity
 
Inheritance in solidity
Inheritance in solidityInheritance in solidity
Inheritance in solidity
 
Interface in solidity
Interface in solidityInterface in solidity
Interface in solidity
 
Abstract contract In Solidity
Abstract contract In SolidityAbstract contract In Solidity
Abstract contract In Solidity
 
Solidity low level logging
Solidity low level loggingSolidity low level logging
Solidity low level logging
 
Solidity- Error Handling
Solidity- Error HandlingSolidity- Error Handling
Solidity- Error Handling
 
Blockchain Introduction
Blockchain IntroductionBlockchain Introduction
Blockchain Introduction
 
Blockchain Webinar
Blockchain WebinarBlockchain Webinar
Blockchain Webinar
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdf
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Intelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdfIntelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdf
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 

Solidity Tutorials- Libraries in solidity

  • 1. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y S O L I D I T Y L I B R A R I E S
  • 2. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com What is Library ? A library is a different type of contract, that doesn't have any storage and cannot hold ether. This is helpful when we want to re-use some piece of code. This does not have payable and fallback function so libraries do not hold ether and do not have any storage. Library function deployed only at one specific address and these functions are called in context of calling contract.
  • 3. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com What is Library ? pragma solidity ^ 0.4.20; library math{ function add(uint _fValue, uint _sValue) public returns(uint){ return _fValue + _sValue; } } contract salary{ function salarywithBouns(uint _salary, uint _bonus) public returns(uint){ return math.add(_salary,_bonus); } }
  • 4. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y confidential @Tutorials Diary  | www.tutorialsdiary.com Using for Keyword We can attach library function to any data type by using "using" and "for" keywords. using A for B; pragma solidity ^ 0.4.20; library math{ function add(uint _fValue, uint _sValue) public returns(uint){ return _fValue + _sValue; } } contract salary{ using math for uint; function salarywithBouns(uint _salary, uint _bonus) public returns(uint){ return _salary.add(_bonus); } }