SlideShare a Scribd company logo
1 of 17
Abstract Factory pattern
application on multi-contract
on-chain deployments
DEJAN RADIĆ
Bločk Conference, Čakovec, Croatia, 15 December, 2018
About me
• Dejan Radić (29)
• MSc in Computer Science (University of Banja Luka)
• Participated on 20+ projects for international clients
as a developer
• Currently CTO at Oroundo (Culture & Tourism)
• Managing 15+ people on 3+ projects
• Attending conferences and meet-ups as a speaker
• Lately interested & passionate about blockchain
Agenda
• Intro
• On-chain contract deployments
• Simple factory pattern approach
• Block gas limit
• Abstract factory pattern application
• Custom contract deployment
• Conclusion
Agenda
• Can smart contract create a new smart contract?
• Can they have the ability to create multiple kinds of
them?
• Is Ethereum platform limited in a way which prohibits
us to easily create such functionality?
• Use of abstract factory pattern instead of simple
factory changes the perspective
• Usage example: building an ICO/UTO/STO/TGE
platform on blockchain (token & crowdsale)
• Example: Creation of fungible (ERC20) and non-
fungible (ERC721) tokens
• UML class diagrams (draw.io)
• Examples in Solidity
• Solidity understanding level: Intermediate
Intro
On-chain contract deployments
• Yes, smart contract can create another smart contract by
using a keyword “new” (usually heap allocation)
• MyContract c1 = MyContract(someAddress);
• MyContract c2 = new MyContract(constructorParams);
• Getting the addresses (which are representing pointers or
references in Solidity) through address(c1) and
address(c2)
• Creating new contract consumes 21 000 gas immediately
• EtherScan source code verification !?
Simple factory
pattern approach
• Factory creates new
items based on
specified type
• Type is specified over
enum
• Both tokens
(bytecodes) are
deployed together
with factory
• Storage costs gas !?
Block gas limit
• Sum of all transaction gas limits in a block can
not exceed a certain value
• Block gas limit is different between the blocks
• New block gas limit is decided by algorithm
and voted by miners
• “Exceeds block gas limit” error shows if
transaction consumes more gas than available
• Values are different between Mainnet and
Ropsten (8m vs 4.7m)
Abstract factory pattern application
Abstract factory pattern application
Interfaces
contract IToken {
function name() public view returns (string memory name);
function symbol() public view returns (string memory symbol);
function balanceOf(address _owner) public view returns (uint);
}
contract ITokenFactory {
function createERC20(string memory name, string memory symbol, uint8 decimals) public returns (ERC20);
function createERC721(string memory name, string memory symbol) public returns (ERC721);
}
• Implementation in Solidity 0.5.1
• 0.5.0 version brought a few breaking changes
• Prefix “I” to emphasize it’s an interface
contract ERC20 is IToken {
string internal _name ;
string internal _symbol;
uint8 internal _decimals;
mapping(address => uint) public balances;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
function name() public view returns (string memory name) {
return _name;
}
function symbol() public view returns (string memory symbol) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function balanceOf(address _owner) public view returns (uint) {
require(_owner != address(0));
return balances[_owner];
}
}
ERC20implementation
contract ERC721 is IToken {
string internal _name ;
string internal _symbol;
mapping(address => uint) public ownedTokensCount;
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
}
function name() public view returns (string memory name) {
return _name;
}
function symbol() public view returns (string memory symbol) {
return _symbol;
}
function balanceOf(address _owner) public view returns (uint) {
return ownedTokensCount[_owner];
}
}
ERC721implementation
Concrete factory implementations
contract ERC20Factory is ITokenFactory {
function createERC20(string memory name, string memory symbol, uint8 decimals) public returns (ERC20) {
return new ERC20(name, symbol, decimals);
}
function createERC721(string memory name, string memory symbol) public returns (ERC721) {
require(false);
}
}
contract ERC721Factory is ITokenFactory {
function createERC20(string memory name, string memory symbol, uint8 decimals) public returns (ERC20) {
require(false);
}
function createERC721(string memory name, string memory symbol) public returns (ERC721) {
return new ERC721(name, symbol);
}
}
• Client has references (addresses) of all concrete factories
• All creating functions are implemented in all factories
• require(false) or revert() instead of return null
Custom contract deployment
function createCustomContract(bytes _code) public returns (address) {
address deployedAddress;
uint256 successIndication;
assembly {
deployedAddress := create(0, add(_code, 0x20), mload(_code))
successIndication := gt(extcodesize(deployedAddress),0)
}
require(successIndication > 0);
return deployedAddress;
}
• If required contract has more functionalities than the ones
available through factory, there is a way to deploy custom
contract over specified bytecode using assembly functions.
• Compilation over solc.js (through ĐApp)
• use of ERC-165 to check the interface of deployed contract
Conclusion
• Ethereum is still a novel technology
• Thinking outside of the box
• Divide and conquer technique lead to
separation of concerns
• Multiple separate deployments of concrete
factories overcome the inherent block size
limitations
• Application of design patterns, not just
because of standardization, but because of
different view of a problem
• Get a habit of drawing things, it can help with
change of perspective
Questions !?
Thank you !!!

More Related Content

Similar to Abstract Factory pattern application on multi-contract on-chain deployments

Enforce Consistentcy with Clean Architecture
Enforce Consistentcy with Clean ArchitectureEnforce Consistentcy with Clean Architecture
Enforce Consistentcy with Clean ArchitectureFlorin Coros
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureFlorin Coros
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidityEmanuel Mota
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureFlorin Coros
 
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 [Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 Yunho Maeng
 
Automatically Documenting Program Changes
Automatically Documenting Program ChangesAutomatically Documenting Program Changes
Automatically Documenting Program ChangesRay Buse
 
Madeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable HardwareMadeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable HardwareESUG
 
Enforce Consistency through Application Infrastructure - Florin Coros
Enforce Consistency through Application Infrastructure - Florin CorosEnforce Consistency through Application Infrastructure - Florin Coros
Enforce Consistency through Application Infrastructure - Florin CorosITCamp
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureFlorin Coros
 
Performance Verification for ESL Design Methodology from AADL Models
Performance Verification for ESL Design Methodology from AADL ModelsPerformance Verification for ESL Design Methodology from AADL Models
Performance Verification for ESL Design Methodology from AADL ModelsSpace Codesign
 
Integration of Cincom Smalltalk Systems
Integration of Cincom Smalltalk SystemsIntegration of Cincom Smalltalk Systems
Integration of Cincom Smalltalk SystemsESUG
 
Creating a Plug-In Architecture
Creating a Plug-In ArchitectureCreating a Plug-In Architecture
Creating a Plug-In Architectureondrejbalas
 
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009ken.egozi
 
Odog : A Framework for Concurrent and Distributed software design
Odog : A Framework for Concurrent and Distributed software designOdog : A Framework for Concurrent and Distributed software design
Odog : A Framework for Concurrent and Distributed software designivanjokerbr
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key conceptsICS
 
Get together on getting more out of typescript & angular 2
Get together on getting more out of typescript & angular 2Get together on getting more out of typescript & angular 2
Get together on getting more out of typescript & angular 2Ruben Haeck
 
An Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprAn Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprPrabhavathi P
 

Similar to Abstract Factory pattern application on multi-contract on-chain deployments (20)

Enforce Consistentcy with Clean Architecture
Enforce Consistentcy with Clean ArchitectureEnforce Consistentcy with Clean Architecture
Enforce Consistentcy with Clean Architecture
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
 
lecture_32.pptx
lecture_32.pptxlecture_32.pptx
lecture_32.pptx
 
Lecture 32
Lecture 32Lecture 32
Lecture 32
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidity
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
 
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 [Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
 
Automatically Documenting Program Changes
Automatically Documenting Program ChangesAutomatically Documenting Program Changes
Automatically Documenting Program Changes
 
Madeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable HardwareMadeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable Hardware
 
Enforce Consistency through Application Infrastructure - Florin Coros
Enforce Consistency through Application Infrastructure - Florin CorosEnforce Consistency through Application Infrastructure - Florin Coros
Enforce Consistency through Application Infrastructure - Florin Coros
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
 
Performance Verification for ESL Design Methodology from AADL Models
Performance Verification for ESL Design Methodology from AADL ModelsPerformance Verification for ESL Design Methodology from AADL Models
Performance Verification for ESL Design Methodology from AADL Models
 
Integration of Cincom Smalltalk Systems
Integration of Cincom Smalltalk SystemsIntegration of Cincom Smalltalk Systems
Integration of Cincom Smalltalk Systems
 
Creating a Plug-In Architecture
Creating a Plug-In ArchitectureCreating a Plug-In Architecture
Creating a Plug-In Architecture
 
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
 
Odog : A Framework for Concurrent and Distributed software design
Odog : A Framework for Concurrent and Distributed software designOdog : A Framework for Concurrent and Distributed software design
Odog : A Framework for Concurrent and Distributed software design
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key concepts
 
Get together on getting more out of typescript & angular 2
Get together on getting more out of typescript & angular 2Get together on getting more out of typescript & angular 2
Get together on getting more out of typescript & angular 2
 
An Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprAn Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl ppr
 

More from Dejan Radic

A Tale of Two Worlds: Real World and On-chain World
A Tale of Two Worlds: Real World and On-chain WorldA Tale of Two Worlds: Real World and On-chain World
A Tale of Two Worlds: Real World and On-chain WorldDejan Radic
 
Technical challenges of RWA Tokenization
Technical challenges of RWA TokenizationTechnical challenges of RWA Tokenization
Technical challenges of RWA TokenizationDejan Radic
 
Sta su to Blockchain, Crypto i Web3?
Sta su to Blockchain, Crypto i Web3?Sta su to Blockchain, Crypto i Web3?
Sta su to Blockchain, Crypto i Web3?Dejan Radic
 
Privacy-enhancing technologies and Blockchain
Privacy-enhancing technologies and BlockchainPrivacy-enhancing technologies and Blockchain
Privacy-enhancing technologies and BlockchainDejan Radic
 
Blockchain beyond DeFi
Blockchain beyond DeFiBlockchain beyond DeFi
Blockchain beyond DeFiDejan Radic
 
Data(base) taxonomy
Data(base) taxonomyData(base) taxonomy
Data(base) taxonomyDejan Radic
 
Paillier Cryptosystem
Paillier CryptosystemPaillier Cryptosystem
Paillier CryptosystemDejan Radic
 
Da li su Vasi podaci sigurni u Cloud-u?
Da li su Vasi podaci sigurni u Cloud-u?Da li su Vasi podaci sigurni u Cloud-u?
Da li su Vasi podaci sigurni u Cloud-u?Dejan Radic
 
Internal and external positioning in mobile and web applications
Internal and external positioning in mobile and web applicationsInternal and external positioning in mobile and web applications
Internal and external positioning in mobile and web applicationsDejan Radic
 
Influence of schema-less approach on database authorization
Influence of schema-less approach on database authorizationInfluence of schema-less approach on database authorization
Influence of schema-less approach on database authorizationDejan Radic
 
Initial sprint velocity problem
Initial sprint velocity problemInitial sprint velocity problem
Initial sprint velocity problemDejan Radic
 

More from Dejan Radic (12)

A Tale of Two Worlds: Real World and On-chain World
A Tale of Two Worlds: Real World and On-chain WorldA Tale of Two Worlds: Real World and On-chain World
A Tale of Two Worlds: Real World and On-chain World
 
Technical challenges of RWA Tokenization
Technical challenges of RWA TokenizationTechnical challenges of RWA Tokenization
Technical challenges of RWA Tokenization
 
Sta su to Blockchain, Crypto i Web3?
Sta su to Blockchain, Crypto i Web3?Sta su to Blockchain, Crypto i Web3?
Sta su to Blockchain, Crypto i Web3?
 
Privacy-enhancing technologies and Blockchain
Privacy-enhancing technologies and BlockchainPrivacy-enhancing technologies and Blockchain
Privacy-enhancing technologies and Blockchain
 
Blockchain beyond DeFi
Blockchain beyond DeFiBlockchain beyond DeFi
Blockchain beyond DeFi
 
Data(base) taxonomy
Data(base) taxonomyData(base) taxonomy
Data(base) taxonomy
 
Paillier Cryptosystem
Paillier CryptosystemPaillier Cryptosystem
Paillier Cryptosystem
 
Da li su Vasi podaci sigurni u Cloud-u?
Da li su Vasi podaci sigurni u Cloud-u?Da li su Vasi podaci sigurni u Cloud-u?
Da li su Vasi podaci sigurni u Cloud-u?
 
Internal and external positioning in mobile and web applications
Internal and external positioning in mobile and web applicationsInternal and external positioning in mobile and web applications
Internal and external positioning in mobile and web applications
 
Ethereum Intro
Ethereum IntroEthereum Intro
Ethereum Intro
 
Influence of schema-less approach on database authorization
Influence of schema-less approach on database authorizationInfluence of schema-less approach on database authorization
Influence of schema-less approach on database authorization
 
Initial sprint velocity problem
Initial sprint velocity problemInitial sprint velocity problem
Initial sprint velocity problem
 

Recently uploaded

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Abstract Factory pattern application on multi-contract on-chain deployments

  • 1. Abstract Factory pattern application on multi-contract on-chain deployments DEJAN RADIĆ Bločk Conference, Čakovec, Croatia, 15 December, 2018
  • 2. About me • Dejan Radić (29) • MSc in Computer Science (University of Banja Luka) • Participated on 20+ projects for international clients as a developer • Currently CTO at Oroundo (Culture & Tourism) • Managing 15+ people on 3+ projects • Attending conferences and meet-ups as a speaker • Lately interested & passionate about blockchain
  • 3. Agenda • Intro • On-chain contract deployments • Simple factory pattern approach • Block gas limit • Abstract factory pattern application • Custom contract deployment • Conclusion Agenda
  • 4. • Can smart contract create a new smart contract? • Can they have the ability to create multiple kinds of them? • Is Ethereum platform limited in a way which prohibits us to easily create such functionality? • Use of abstract factory pattern instead of simple factory changes the perspective • Usage example: building an ICO/UTO/STO/TGE platform on blockchain (token & crowdsale) • Example: Creation of fungible (ERC20) and non- fungible (ERC721) tokens • UML class diagrams (draw.io) • Examples in Solidity • Solidity understanding level: Intermediate Intro
  • 5. On-chain contract deployments • Yes, smart contract can create another smart contract by using a keyword “new” (usually heap allocation) • MyContract c1 = MyContract(someAddress); • MyContract c2 = new MyContract(constructorParams); • Getting the addresses (which are representing pointers or references in Solidity) through address(c1) and address(c2) • Creating new contract consumes 21 000 gas immediately • EtherScan source code verification !?
  • 6. Simple factory pattern approach • Factory creates new items based on specified type • Type is specified over enum • Both tokens (bytecodes) are deployed together with factory • Storage costs gas !?
  • 7. Block gas limit • Sum of all transaction gas limits in a block can not exceed a certain value • Block gas limit is different between the blocks • New block gas limit is decided by algorithm and voted by miners • “Exceeds block gas limit” error shows if transaction consumes more gas than available • Values are different between Mainnet and Ropsten (8m vs 4.7m)
  • 10. Interfaces contract IToken { function name() public view returns (string memory name); function symbol() public view returns (string memory symbol); function balanceOf(address _owner) public view returns (uint); } contract ITokenFactory { function createERC20(string memory name, string memory symbol, uint8 decimals) public returns (ERC20); function createERC721(string memory name, string memory symbol) public returns (ERC721); } • Implementation in Solidity 0.5.1 • 0.5.0 version brought a few breaking changes • Prefix “I” to emphasize it’s an interface
  • 11. contract ERC20 is IToken { string internal _name ; string internal _symbol; uint8 internal _decimals; mapping(address => uint) public balances; constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } function name() public view returns (string memory name) { return _name; } function symbol() public view returns (string memory symbol) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function balanceOf(address _owner) public view returns (uint) { require(_owner != address(0)); return balances[_owner]; } } ERC20implementation
  • 12. contract ERC721 is IToken { string internal _name ; string internal _symbol; mapping(address => uint) public ownedTokensCount; constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; } function name() public view returns (string memory name) { return _name; } function symbol() public view returns (string memory symbol) { return _symbol; } function balanceOf(address _owner) public view returns (uint) { return ownedTokensCount[_owner]; } } ERC721implementation
  • 13. Concrete factory implementations contract ERC20Factory is ITokenFactory { function createERC20(string memory name, string memory symbol, uint8 decimals) public returns (ERC20) { return new ERC20(name, symbol, decimals); } function createERC721(string memory name, string memory symbol) public returns (ERC721) { require(false); } } contract ERC721Factory is ITokenFactory { function createERC20(string memory name, string memory symbol, uint8 decimals) public returns (ERC20) { require(false); } function createERC721(string memory name, string memory symbol) public returns (ERC721) { return new ERC721(name, symbol); } } • Client has references (addresses) of all concrete factories • All creating functions are implemented in all factories • require(false) or revert() instead of return null
  • 14. Custom contract deployment function createCustomContract(bytes _code) public returns (address) { address deployedAddress; uint256 successIndication; assembly { deployedAddress := create(0, add(_code, 0x20), mload(_code)) successIndication := gt(extcodesize(deployedAddress),0) } require(successIndication > 0); return deployedAddress; } • If required contract has more functionalities than the ones available through factory, there is a way to deploy custom contract over specified bytecode using assembly functions. • Compilation over solc.js (through ĐApp) • use of ERC-165 to check the interface of deployed contract
  • 15. Conclusion • Ethereum is still a novel technology • Thinking outside of the box • Divide and conquer technique lead to separation of concerns • Multiple separate deployments of concrete factories overcome the inherent block size limitations • Application of design patterns, not just because of standardization, but because of different view of a problem • Get a habit of drawing things, it can help with change of perspective