SlideShare ist ein Scribd-Unternehmen logo
1 von 36
IPFS AND SMART
CONTRACTS
Interplanetary File System
+ Smart Contracts
Hands-on
THERE ARE SOME SMART CONTRACT
USE CASES WHERE STORAGE OF
LARGE AMOUNT OF DATA IS NEEDED
Gov Records Trade Finance
Title Recording Supply Chain
HOW EXPENSIVE IS IT TO STORE
DATA ON BOCKCHIN? LET’S CHECK:
pragma solidity ^0.5.0;
contract WriteRandomData {
bytes32[] randomArray;
constructor() public {
bytes32 rand32 = keccak256(abi.encodePacked(block.timestamp));
for(uint i; i<32; i++) {
rand32 = keccak256(abi.encodePacked(rand32));
randomArray.push(rand32);
}
}
}
788,268 GAS UNITS TO CREATE
THE CONTRACT AND STORE 1KB
OF DATA
LET’S CREATE THE SAME CONTACT
BUT SKIP DATA STORAGE ON
BLOCKCHAIN
pragma solidity ^0.5.0;
contract WriteRandomData {
bytes32[] randomArray;
constructor() public {
bytes32 rand32 = keccak256(abi.encodePacked(block.timestamp));
for(uint i; i<32; i++) {
rand32 = keccak256(abi.encodePacked(rand32));
//randomArray.push(rand32);
}
}
}
73,032 GAS UNITS
LET’S CONVERT IT TO DOLLARS
AND CENTS
1 KB of data storage on Etherium: 788,268-73,032 = 715,236
Gas Units
715,236 Gas Units = 715,236 Gwei (assuming that we set
1Gwei for gas price)
1Gwei = 0.00001908 USD (as of 1/11/2020)
1KB Of storage: $0.00001908* 715,236 = $ 13.64670288
ALTERNATIVES TO STORORING
DATA A DIRECTLY ON BLOCKCHAIN
IPFS ON HIGH LEVEL: PEER-TO-
PEER NETWORK + GIT VERSIONING
Client-Server Network Peer-to-Peer Network
IPFS OBJECT
Data
< 256 kB of binary data
…
Link
Link
Name Hash Size
Link
MERKLE TREE
• Every leaf node is labelled with the
hash of a data block.
• Every non-leaf node is labelled with
the cryptographic hash of the labels
of its child nodes
MERKLE DIERECT ACCYCLIC
GRAPH (DAG)
DAG data structure similar to a Merkle tree but
not so strict:
1. DAG does not need to be balanced
2. Non-leaf nodes are allowed to contain data
Merkle DAG enables uniquely identified,
tamper-resistant and permanently stored
data shared by network nodes.
DAG creates a foundation for Distributed
Hash Table
IPFS PROPERTIES
With the Distributed Hash Table, nodes can store & share data
without central coordination
IPFS is Persistent Data Structure (nothing can be deleted)
Uploaded content is not guaranteed to persist on the network (all
participating nodes should consider participation a voluntary service)
HOW TO STORE AND ACCESS FILES
ON IPFS?
Command line interface https://dist.ipfs.io/#go-ipfs
API https://docs.ipfs.io/reference/api/http/
Libraries for different languages, for example NPM module for
JavaScript: https://www.npmjs.com/package/ipfs-api
INSTALLING IPFS • Installing IPFS Node on
GCP from scratch
CLOUD CONSOLE, CREATE A NEW
INSTANCEhttps://console.cloud.google.com/
OPEN PORT 4001
SSH INTO NEW INSTANCE
INSTALL GO
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update
sudo apt-get install golang-go
go version
INSTALL IPFS
go get -u -d github.com/ipfs/go-ipfs
cd ~/go/src/github.com/ipfs/go-ipfs
make install
START IPFS NODE
cd ~/go/bin
./ipfs init
./ipfs daemon
PUBLISHING TO IPFS
• How to publish files to
the IPFS node
• How to read objects
from IPFS node
PUBLISH A FILE
leybzon@instance-1:~/go/bin$ cd ~
leybzon@instance-1:~$ vi test.html
leybzon@instance-1:~$ ./go/bin/ipfs add -w test.html
added QmTBJ2SCD5Jpkqu3eM6utx4yfviwHBNKGqFgfbP5CcT1zk
test.html
added QmeoBZA3ywRT5wEa6RBuHxF4qaKAK8qSxuxWCr4BpPzT2r 7 B
/ 7 B
[=========================================]
100.00%
CHECK THAT THE FILE WAS
PUBLISHED LOCALLY
leybzon@instance-1:~/go/bin$ ./go/bin/ipfs object get
QmTBJ2SCD5Jpkqu3eM6utx4yfviwHBNKGqFgfbP5CcT1
zk{"Links":[],"Data":"u0008u0002u0012u0007testnnnu0018u0007"}u0
012u0007testnnnu0018u0007"}
START IPFS DAEMON
leybzon@instance-2:~/go/bin$ ~/go/bin/ipfs daemon
Initializing daemon...go-ipfs version: 0.5.0-dev-049d3b0Repo version: 7
System version: amd64/linuxGolang version: go1.13.4
Swarm listening on /ip4/10.128.0.5/tcp/4001
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/10.128.0.5/tcp/4001
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready
USE INFURA GATEWAY TO GET THE
OBJECT
leybzon@instance-1:~/go/bin$ curl
“https://ipfs.infura.io:5001/api/v0/cat?arg=QmTBJ2SCD5Jpkqu3eM6utx4yfviwHBNKGqFgfbP
5CcT1zk”
test
SMART CONTRACT +
IPFS
• How to use IPFS objects in
Smart Contracts
• Creating ERC721 Smart
Contract
• Minting tokens connected
to IPFS objects
ERC-721 NFT CONNECTED TO DATA
IPFS
NFT Tokens are
 Unique
 Irreplaceable
 Non-
interchngable
ERC721Full ERC721Mintable
ERC721
ERC721Enumerabl
e
ERC721Metadata
MyNFT
mint1()
mintUniqueTokenT
ERC721 SMART CONTRACT 1/2
pragma solidity ^0.5.0;
import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol';
import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol';
contract MyNFT is ERC721Full, ERC721Mintable {
constructor() ERC721Full("IPFS", "IPFS_DEMO") public {
}
event RecordedIpfsHash(uint256, string);
mapping(uint256 => string) _documents;
function mint1(uint256 _uid, string memory _ipfsHash) public{
_mint(msg.sender, _uid);
_documents[_uid] = _ipfsHash;
emit RecordedIpfsHash(_uid, _ipfsHash);
}
ERC721 SMART CONTRACT 2/2
…
function mintUniqueTokenTo(
address _to,
uint256 _tokenId,
string memory _tokenURI,
string memory _ipfsHash
) public
{
super._mint(_to, _tokenId);
super._setTokenURI(_tokenId, _tokenURI);
_documents[_tokenId] = _ipfsHash;
emit RecordedIpfsHash(_tokenId, _ipfsHash);
}
}
DEPLOYING SMART CONTRACT TO
BLOCKCHAIN
CALLING SMART CONTRACT TO
ISSUE NEW TOKEN
VERIFYING THAT THE TOKEN WAS
CREATED SUCCESSFULLY
QUESTIONS
ANOUNCEMENTS
STAY IN TOUCH
Gene Leybzon https://www.linkedin.com/in/leybzon/
https://www.meetup.com/members/90744
20/
https://www.leybzon.com

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Introduction to IPFS & Filecoin
Introduction to IPFS & FilecoinIntroduction to IPFS & Filecoin
Introduction to IPFS & Filecoin
 
IPSec VPN & IPSec Protocols
IPSec VPN & IPSec ProtocolsIPSec VPN & IPSec Protocols
IPSec VPN & IPSec Protocols
 
GRE (Generic Routing Encapsulation)
GRE (Generic Routing Encapsulation)GRE (Generic Routing Encapsulation)
GRE (Generic Routing Encapsulation)
 
Hyperledger fabric 20180528
Hyperledger fabric 20180528Hyperledger fabric 20180528
Hyperledger fabric 20180528
 
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
Understanding Proof of Work (PoW) and Proof of Stake (PoS) AlgorithmsUnderstanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
 
Ipfs : InterPlanetary File System
Ipfs : InterPlanetary File SystemIpfs : InterPlanetary File System
Ipfs : InterPlanetary File System
 
Introduction to OpenStack
Introduction to OpenStackIntroduction to OpenStack
Introduction to OpenStack
 
Get Hands-On with NGINX and QUIC+HTTP/3
Get Hands-On with NGINX and QUIC+HTTP/3Get Hands-On with NGINX and QUIC+HTTP/3
Get Hands-On with NGINX and QUIC+HTTP/3
 
IPv6
IPv6IPv6
IPv6
 
Ovs dpdk hwoffload way to full offload
Ovs dpdk hwoffload way to full offloadOvs dpdk hwoffload way to full offload
Ovs dpdk hwoffload way to full offload
 
6LoWPAN: An Open IoT Networking Protocol
6LoWPAN: An Open IoT Networking Protocol6LoWPAN: An Open IoT Networking Protocol
6LoWPAN: An Open IoT Networking Protocol
 
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
 
Chapter 2 point-to-point protocol (ppp)
Chapter 2   point-to-point protocol (ppp)Chapter 2   point-to-point protocol (ppp)
Chapter 2 point-to-point protocol (ppp)
 
Hyperledger Fabric in a Nutshell
Hyperledger Fabric in a NutshellHyperledger Fabric in a Nutshell
Hyperledger Fabric in a Nutshell
 
File transfer protocol (ftp)
File transfer protocol (ftp)File transfer protocol (ftp)
File transfer protocol (ftp)
 
Web servers presentacion
Web servers presentacionWeb servers presentacion
Web servers presentacion
 
iSCSI (Internet Small Computer System Interface)
iSCSI (Internet Small Computer System Interface)iSCSI (Internet Small Computer System Interface)
iSCSI (Internet Small Computer System Interface)
 
An Introduction to OpenStack
An Introduction to OpenStackAn Introduction to OpenStack
An Introduction to OpenStack
 
PCP
PCPPCP
PCP
 
Module: Content Exchange in IPFS
Module: Content Exchange in IPFSModule: Content Exchange in IPFS
Module: Content Exchange in IPFS
 

Ähnlich wie InterPlanetary File System (IPFS)

Ähnlich wie InterPlanetary File System (IPFS) (20)

Web3 File Storage Options
Web3 File Storage OptionsWeb3 File Storage Options
Web3 File Storage Options
 
Dayta AI Seminar - Kubernetes, Docker and AI on Cloud
Dayta AI Seminar - Kubernetes, Docker and AI on CloudDayta AI Seminar - Kubernetes, Docker and AI on Cloud
Dayta AI Seminar - Kubernetes, Docker and AI on Cloud
 
Effective Building your Platform with Kubernetes == Keep it Simple
Effective Building your Platform with Kubernetes == Keep it Simple Effective Building your Platform with Kubernetes == Keep it Simple
Effective Building your Platform with Kubernetes == Keep it Simple
 
Linux Security and How Web Browser Sandboxes Really Work (Security Researcher...
Linux Security and How Web Browser Sandboxes Really Work (Security Researcher...Linux Security and How Web Browser Sandboxes Really Work (Security Researcher...
Linux Security and How Web Browser Sandboxes Really Work (Security Researcher...
 
App Deployment on Cloud
App Deployment on CloudApp Deployment on Cloud
App Deployment on Cloud
 
Super-NetOps Source of Truth
Super-NetOps Source of TruthSuper-NetOps Source of Truth
Super-NetOps Source of Truth
 
Learn how to build decentralized and serverless html5 applications with embar...
Learn how to build decentralized and serverless html5 applications with embar...Learn how to build decentralized and serverless html5 applications with embar...
Learn how to build decentralized and serverless html5 applications with embar...
 
Learn how to build decentralized and serverless html5 applications with Embar...
Learn how to build decentralized and serverless html5 applications with Embar...Learn how to build decentralized and serverless html5 applications with Embar...
Learn how to build decentralized and serverless html5 applications with Embar...
 
Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6
 
IoT Edge Data Processing with NVidia Jetson Nano oct 3 2019
IoT  Edge Data Processing with NVidia Jetson Nano oct 3 2019IoT  Edge Data Processing with NVidia Jetson Nano oct 3 2019
IoT Edge Data Processing with NVidia Jetson Nano oct 3 2019
 
Linux Security APIs and the Chromium Sandbox (SwedenCpp Meetup 2017)
Linux Security APIs and the Chromium Sandbox (SwedenCpp Meetup 2017)Linux Security APIs and the Chromium Sandbox (SwedenCpp Meetup 2017)
Linux Security APIs and the Chromium Sandbox (SwedenCpp Meetup 2017)
 
Make stateful apps in Kubernetes a no brainer with Pure Storage and GitOps
Make stateful apps in Kubernetes a no brainer with Pure Storage and GitOpsMake stateful apps in Kubernetes a no brainer with Pure Storage and GitOps
Make stateful apps in Kubernetes a no brainer with Pure Storage and GitOps
 
Sandboxing WebKitGTK (GUADEC 2019)
Sandboxing WebKitGTK (GUADEC 2019)Sandboxing WebKitGTK (GUADEC 2019)
Sandboxing WebKitGTK (GUADEC 2019)
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in Kubernetes
 
Ceph Day Bring Ceph To Enterprise
Ceph Day Bring Ceph To EnterpriseCeph Day Bring Ceph To Enterprise
Ceph Day Bring Ceph To Enterprise
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
 
GE Predix 新手入门 赵锴 物联网_IoT
GE Predix 新手入门 赵锴 物联网_IoTGE Predix 新手入门 赵锴 物联网_IoT
GE Predix 新手入门 赵锴 物联网_IoT
 
maxbox starter72 multilanguage coding
maxbox starter72 multilanguage codingmaxbox starter72 multilanguage coding
maxbox starter72 multilanguage coding
 
MongoDB.local Austin 2018: MongoDB Ops Manager + Kubernetes
MongoDB.local Austin 2018: MongoDB Ops Manager + KubernetesMongoDB.local Austin 2018: MongoDB Ops Manager + Kubernetes
MongoDB.local Austin 2018: MongoDB Ops Manager + Kubernetes
 

Mehr von Gene Leybzon

Non-fungible tokens (nfts)
Non-fungible tokens (nfts)Non-fungible tokens (nfts)
Non-fungible tokens (nfts)
Gene Leybzon
 

Mehr von Gene Leybzon (20)

Generative AI Application Development using LangChain and LangFlow
Generative AI Application Development using LangChain and LangFlowGenerative AI Application Development using LangChain and LangFlow
Generative AI Application Development using LangChain and LangFlow
 
Chat GPTs
Chat GPTsChat GPTs
Chat GPTs
 
Generative AI Use cases for Enterprise - Second Session
Generative AI Use cases for Enterprise - Second SessionGenerative AI Use cases for Enterprise - Second Session
Generative AI Use cases for Enterprise - Second Session
 
Generative AI Use-cases for Enterprise - First Session
Generative AI Use-cases for Enterprise - First SessionGenerative AI Use-cases for Enterprise - First Session
Generative AI Use-cases for Enterprise - First Session
 
Non-fungible tokens (nfts)
Non-fungible tokens (nfts)Non-fungible tokens (nfts)
Non-fungible tokens (nfts)
 
Introduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxIntroduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptx
 
Ethereum in Enterprise.pptx
Ethereum in Enterprise.pptxEthereum in Enterprise.pptx
Ethereum in Enterprise.pptx
 
ERC-4907 Rentable NFT Standard.pptx
ERC-4907 Rentable NFT Standard.pptxERC-4907 Rentable NFT Standard.pptx
ERC-4907 Rentable NFT Standard.pptx
 
Onchain Decentralized Governance 2.pptx
Onchain Decentralized Governance 2.pptxOnchain Decentralized Governance 2.pptx
Onchain Decentralized Governance 2.pptx
 
Onchain Decentralized Governance.pptx
Onchain Decentralized Governance.pptxOnchain Decentralized Governance.pptx
Onchain Decentralized Governance.pptx
 
Web3 Full Stack Development
Web3 Full Stack DevelopmentWeb3 Full Stack Development
Web3 Full Stack Development
 
Instantly tradeable NFT contracts based on ERC-1155 standard
Instantly tradeable NFT contracts based on ERC-1155 standardInstantly tradeable NFT contracts based on ERC-1155 standard
Instantly tradeable NFT contracts based on ERC-1155 standard
 
Non-fungible tokens. From smart contract code to marketplace
Non-fungible tokens. From smart contract code to marketplaceNon-fungible tokens. From smart contract code to marketplace
Non-fungible tokens. From smart contract code to marketplace
 
The Art of non-fungible tokens
The Art of non-fungible tokensThe Art of non-fungible tokens
The Art of non-fungible tokens
 
Graph protocol for accessing information about blockchains and d apps
Graph protocol for accessing information about blockchains and d appsGraph protocol for accessing information about blockchains and d apps
Graph protocol for accessing information about blockchains and d apps
 
Substrate Framework
Substrate FrameworkSubstrate Framework
Substrate Framework
 
Chainlink
ChainlinkChainlink
Chainlink
 
OpenZeppelin + Remix + BNB smart chain
OpenZeppelin + Remix + BNB smart chainOpenZeppelin + Remix + BNB smart chain
OpenZeppelin + Remix + BNB smart chain
 
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains
Chainlink, Cosmos, Kusama, Polkadot:   Approaches to the Internet of BlockchainsChainlink, Cosmos, Kusama, Polkadot:   Approaches to the Internet of Blockchains
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains
 
Dex and Uniswap
Dex and UniswapDex and Uniswap
Dex and Uniswap
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

InterPlanetary File System (IPFS)

  • 1. IPFS AND SMART CONTRACTS Interplanetary File System + Smart Contracts Hands-on
  • 2. THERE ARE SOME SMART CONTRACT USE CASES WHERE STORAGE OF LARGE AMOUNT OF DATA IS NEEDED Gov Records Trade Finance Title Recording Supply Chain
  • 3. HOW EXPENSIVE IS IT TO STORE DATA ON BOCKCHIN? LET’S CHECK: pragma solidity ^0.5.0; contract WriteRandomData { bytes32[] randomArray; constructor() public { bytes32 rand32 = keccak256(abi.encodePacked(block.timestamp)); for(uint i; i<32; i++) { rand32 = keccak256(abi.encodePacked(rand32)); randomArray.push(rand32); } } }
  • 4. 788,268 GAS UNITS TO CREATE THE CONTRACT AND STORE 1KB OF DATA
  • 5. LET’S CREATE THE SAME CONTACT BUT SKIP DATA STORAGE ON BLOCKCHAIN pragma solidity ^0.5.0; contract WriteRandomData { bytes32[] randomArray; constructor() public { bytes32 rand32 = keccak256(abi.encodePacked(block.timestamp)); for(uint i; i<32; i++) { rand32 = keccak256(abi.encodePacked(rand32)); //randomArray.push(rand32); } } }
  • 7. LET’S CONVERT IT TO DOLLARS AND CENTS 1 KB of data storage on Etherium: 788,268-73,032 = 715,236 Gas Units 715,236 Gas Units = 715,236 Gwei (assuming that we set 1Gwei for gas price) 1Gwei = 0.00001908 USD (as of 1/11/2020) 1KB Of storage: $0.00001908* 715,236 = $ 13.64670288
  • 8. ALTERNATIVES TO STORORING DATA A DIRECTLY ON BLOCKCHAIN
  • 9. IPFS ON HIGH LEVEL: PEER-TO- PEER NETWORK + GIT VERSIONING Client-Server Network Peer-to-Peer Network
  • 10. IPFS OBJECT Data < 256 kB of binary data … Link Link Name Hash Size Link
  • 11. MERKLE TREE • Every leaf node is labelled with the hash of a data block. • Every non-leaf node is labelled with the cryptographic hash of the labels of its child nodes
  • 12. MERKLE DIERECT ACCYCLIC GRAPH (DAG) DAG data structure similar to a Merkle tree but not so strict: 1. DAG does not need to be balanced 2. Non-leaf nodes are allowed to contain data Merkle DAG enables uniquely identified, tamper-resistant and permanently stored data shared by network nodes. DAG creates a foundation for Distributed Hash Table
  • 13. IPFS PROPERTIES With the Distributed Hash Table, nodes can store & share data without central coordination IPFS is Persistent Data Structure (nothing can be deleted) Uploaded content is not guaranteed to persist on the network (all participating nodes should consider participation a voluntary service)
  • 14. HOW TO STORE AND ACCESS FILES ON IPFS? Command line interface https://dist.ipfs.io/#go-ipfs API https://docs.ipfs.io/reference/api/http/ Libraries for different languages, for example NPM module for JavaScript: https://www.npmjs.com/package/ipfs-api
  • 15. INSTALLING IPFS • Installing IPFS Node on GCP from scratch
  • 16. CLOUD CONSOLE, CREATE A NEW INSTANCEhttps://console.cloud.google.com/
  • 18. SSH INTO NEW INSTANCE
  • 19. INSTALL GO sudo add-apt-repository ppa:longsleep/golang-backports sudo apt-get update sudo apt-get install golang-go go version
  • 20. INSTALL IPFS go get -u -d github.com/ipfs/go-ipfs cd ~/go/src/github.com/ipfs/go-ipfs make install
  • 21. START IPFS NODE cd ~/go/bin ./ipfs init ./ipfs daemon
  • 22. PUBLISHING TO IPFS • How to publish files to the IPFS node • How to read objects from IPFS node
  • 23. PUBLISH A FILE leybzon@instance-1:~/go/bin$ cd ~ leybzon@instance-1:~$ vi test.html leybzon@instance-1:~$ ./go/bin/ipfs add -w test.html added QmTBJ2SCD5Jpkqu3eM6utx4yfviwHBNKGqFgfbP5CcT1zk test.html added QmeoBZA3ywRT5wEa6RBuHxF4qaKAK8qSxuxWCr4BpPzT2r 7 B / 7 B [=========================================] 100.00%
  • 24. CHECK THAT THE FILE WAS PUBLISHED LOCALLY leybzon@instance-1:~/go/bin$ ./go/bin/ipfs object get QmTBJ2SCD5Jpkqu3eM6utx4yfviwHBNKGqFgfbP5CcT1 zk{"Links":[],"Data":"u0008u0002u0012u0007testnnnu0018u0007"}u0 012u0007testnnnu0018u0007"}
  • 25. START IPFS DAEMON leybzon@instance-2:~/go/bin$ ~/go/bin/ipfs daemon Initializing daemon...go-ipfs version: 0.5.0-dev-049d3b0Repo version: 7 System version: amd64/linuxGolang version: go1.13.4 Swarm listening on /ip4/10.128.0.5/tcp/4001 Swarm listening on /ip4/127.0.0.1/tcp/4001 Swarm listening on /ip6/::1/tcp/4001 Swarm listening on /p2p-circuit Swarm announcing /ip4/10.128.0.5/tcp/4001 Swarm announcing /ip4/127.0.0.1/tcp/4001 Swarm announcing /ip6/::1/tcp/4001 API server listening on /ip4/127.0.0.1/tcp/5001 WebUI: http://127.0.0.1:5001/webui Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080 Daemon is ready
  • 26. USE INFURA GATEWAY TO GET THE OBJECT leybzon@instance-1:~/go/bin$ curl “https://ipfs.infura.io:5001/api/v0/cat?arg=QmTBJ2SCD5Jpkqu3eM6utx4yfviwHBNKGqFgfbP 5CcT1zk” test
  • 27. SMART CONTRACT + IPFS • How to use IPFS objects in Smart Contracts • Creating ERC721 Smart Contract • Minting tokens connected to IPFS objects
  • 28. ERC-721 NFT CONNECTED TO DATA IPFS NFT Tokens are  Unique  Irreplaceable  Non- interchngable ERC721Full ERC721Mintable ERC721 ERC721Enumerabl e ERC721Metadata MyNFT mint1() mintUniqueTokenT
  • 29. ERC721 SMART CONTRACT 1/2 pragma solidity ^0.5.0; import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol'; import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol'; contract MyNFT is ERC721Full, ERC721Mintable { constructor() ERC721Full("IPFS", "IPFS_DEMO") public { } event RecordedIpfsHash(uint256, string); mapping(uint256 => string) _documents; function mint1(uint256 _uid, string memory _ipfsHash) public{ _mint(msg.sender, _uid); _documents[_uid] = _ipfsHash; emit RecordedIpfsHash(_uid, _ipfsHash); }
  • 30. ERC721 SMART CONTRACT 2/2 … function mintUniqueTokenTo( address _to, uint256 _tokenId, string memory _tokenURI, string memory _ipfsHash ) public { super._mint(_to, _tokenId); super._setTokenURI(_tokenId, _tokenURI); _documents[_tokenId] = _ipfsHash; emit RecordedIpfsHash(_tokenId, _ipfsHash); } }
  • 31. DEPLOYING SMART CONTRACT TO BLOCKCHAIN
  • 32. CALLING SMART CONTRACT TO ISSUE NEW TOKEN
  • 33. VERIFYING THAT THE TOKEN WAS CREATED SUCCESSFULLY
  • 36. STAY IN TOUCH Gene Leybzon https://www.linkedin.com/in/leybzon/ https://www.meetup.com/members/90744 20/ https://www.leybzon.com

Hinweis der Redaktion

  1. https://www.ccn.com/smart-contracts-12-use-cases-for-business-and-beyond/
  2. https://kovan.etherscan.io/tx/0x878fea422658c0226cae626303aa814f7016fb0bbaca8f96a87b913e7975b634
  3. https://kovan.etherscan.io/tx/0xae695b8748620d89d08f7480723138de1cffdc39a40c6d72e210a681cab1fc27
  4. https://ethgasstation.info/
  5. https://hackernoon.com/storagepedia-an-encyclopedia-of-5-blockchain-storage-platform-8aa13c630ace
  6. https://en.wikipedia.org/wiki/BitTorrent
  7. https://medium.com/@ConsenSys/an-introduction-to-ipfs-9bba4860abd0
  8. https://en.wikipedia.org/wiki/Merkle_tree every leaf node is labelled with the hash of a data block, and every non-leaf node is labelled with the cryptographic hash of the labels of its child nodes
  9. https://en.wikipedia.org/wiki/Merkle_tree every leaf node is labelled with the hash of a data block, and every non-leaf node is labelled with the cryptographic hash of the labels of its child nodes Image from https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSG4yZSyyw91ZphCLwGfIu2cyP3bD2GEu8uy2FQXX1vvFEvkQqn&s
  10. https://console.cloud.google.com/ https://console.cloud.google.com/compute/instances?project=pbs-network-test&instancessize=50 “Create Instance” Select Ubuntu as boot disk
  11. https://console.cloud.google.com/networking/firewalls/add?project=pbs-network-test&authuser=0&hl=en
  12. ./go/bin/ipfs object get <hash> ./go/bin/ipfs cat <hash>
  13. ~/go/bin/ipfs daemon
  14. https://ipfs.infura.io:5001/api/v0/cat?arg=QmaqZ2DhwyxRFuYFrE3wxRwXCeRjZL1F8R5yxTfAUNE2Tx ./go/bin/ipfs cat QmaqZ2DhwyxRFuYFrE3wxRwXCeRjZL1F8R5yxTfAUNE2Tx
  15. https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721Full.sol https://github.com/leybzon/solidity-baby-steps/blob/master/contracts/79_ERC_721_IPFS.sol
  16. https://github.com/leybzon/solidity-baby-steps/blob/master/contracts/79_ERC_721_IPFS.sol
  17. https://github.com/leybzon/solidity-baby-steps/blob/master/contracts/79_ERC_721_IPFS.sol
  18. POST to https://{{blockchain}}.apidapp.com/1/contract
  19. Calling mintUniqueTokenTo({{id}},{{$randomInt}}{{$randomInt}},{{$randomString}},'QmTBJ2SCD5Jpkqu3eM6utx4yfviwHBNKGqFgfbP5CcT1zk')
  20. https://kovan.etherscan.io/tx/0x09998673de181648fbd06ee732e8e10ea00810cfbcc3aac8c8dee8e1b39883a0