Wednesday, July 8, 2020

What are Smart Contracts

What are Smart Contracts What are Smart Contracts? A Beginners Guide To Smart Contracts Back Home Categories Online Courses Mock Interviews Webinars NEW Community Write for Us Categories Artificial Intelligence AI vs Machine Learning vs Deep LearningMachine Learning AlgorithmsArtificial Intelligence TutorialWhat is Deep LearningDeep Learning TutorialInstall TensorFlowDeep Learning with PythonBackpropagationTensorFlow TutorialConvolutional Neural Network TutorialVIEW ALL BI and Visualization What is TableauTableau TutorialTableau Interview QuestionsWhat is InformaticaInformatica Interview QuestionsPower BI TutorialPower BI Interview QuestionsOLTP vs OLAPQlikView TutorialAdvanced Excel Formulas TutorialVIEW ALL Big Data What is HadoopHadoop ArchitectureHadoop TutorialHadoop Interview QuestionsHadoop EcosystemData Science vs Big Data vs Data AnalyticsWhat is Big DataMapReduce TutorialPig TutorialSpark TutorialSpark Interview QuestionsBig Data TutorialHive TutorialVIEW ALL Blockchain Blockchain TutorialWhat is BlockchainHyperledger FabricWhat Is EthereumEthereum TutorialB lockchain ApplicationsSolidity TutorialBlockchain ProgrammingHow Blockchain WorksVIEW ALL Cloud Computing What is AWSAWS TutorialAWS CertificationAzure Interview QuestionsAzure TutorialWhat Is Cloud ComputingWhat Is SalesforceIoT TutorialSalesforce TutorialSalesforce Interview QuestionsVIEW ALL Cyber Security Cloud SecurityWhat is CryptographyNmap TutorialSQL Injection AttacksHow To Install Kali LinuxHow to become an Ethical Hacker?Footprinting in Ethical HackingNetwork Scanning for Ethical HackingARP SpoofingApplication SecurityVIEW ALL Data Science Python Pandas TutorialWhat is Machine LearningMachine Learning TutorialMachine Learning ProjectsMachine Learning Interview QuestionsWhat Is Data ScienceSAS TutorialR TutorialData Science ProjectsHow to become a data scientistData Science Interview QuestionsData Scientist SalaryVIEW ALL Data Warehousing and ETL What is Data WarehouseDimension Table in Data WarehousingData Warehousing Interview QuestionsData warehouse architectureTalend T utorialTalend ETL ToolTalend Interview QuestionsFact Table and its TypesInformatica TransformationsInformatica TutorialVIEW ALL Databases What is MySQLMySQL Data TypesSQL JoinsSQL Data TypesWhat is MongoDBMongoDB Interview QuestionsMySQL TutorialSQL Interview QuestionsSQL CommandsMySQL Interview QuestionsVIEW ALL DevOps What is DevOpsDevOps vs AgileDevOps ToolsDevOps TutorialHow To Become A DevOps EngineerDevOps Interview QuestionsWhat Is DockerDocker TutorialDocker Interview QuestionsWhat Is ChefWhat Is KubernetesKubernetes TutorialVIEW ALL Front End Web Development What is JavaScript รข€" All You Need To Know About JavaScriptJavaScript TutorialJavaScript Interview QuestionsJavaScript FrameworksAngular TutorialAngular Interview QuestionsWhat is REST API?React TutorialReact vs AngularjQuery TutorialNode TutorialReact Interview QuestionsVIEW ALL Mobile Development Android TutorialAndroid Interview QuestionsAndroid ArchitectureAndroid SQLite DatabaseProgramming s Guide To Smart Contrac ts Last updated on May 22,2019 6K Views Shashank Shashank is a Research Analyst at Edureka. He is an expert in... Shashank is a Research Analyst at Edureka. He is an expert in Blockchain technology with profound knowledge in Ethereum, smart contracts, solidity, distributed networks...1 Comments Bookmark 1 / 4 Blog from Smart Contracts Become a Certified Professional The phrase and concept of Smart Contracts were proposed byNick Szabowith the vision to extend the functionality of electronic transaction methods, such as POS (point of sale), to the digital realm.Smart contracts help you exchange property, shares, or anything of value in a transparent, conflict-free way while avoiding the services of a middleman. Following are the topics that we are going to cover in this Smart Contract blog:What are Smart Contracts?Smart Contracts By Nick SzaboWhy We Need Smart Contracts?Smart Contracts: Complexity As Per Use CasesSmart Contracts Use Case: Healthcare IndustrySmart Contracts Adva ntagesBlockchain Platforms For Writing Smart ContractsTools for Writing Deploying Smart ContractsProgramming Languages For Writing EthereumProperty Transfer Smart ContractWhat are Smart Contracts?Smart contracts are a self-operating computer program that automatically executes when specific conditions are met.Smart Contracts = Trustless ContractsWith smart contracts, you can share anything of value, among strangers in a conflict-free transparent way.You can also think of smart contracts as a Blockchain based vending machine. Just like vending machine are configured to take in dollars to dispense your choice of item, smart contracts use ether as a fuel to execute code based on pre-configured rules.What are Smart Contracts | Deploy Your First Ethereum Smart Contract | EdurekaSmart Contracts By Nick Szabo In his paper, Szabo proposed the execution of a contract for synthetic assets, such as derivatives and bonds. These new securities are formed by combining securities (such as bonds) and derivatives (options and futures) in a wide variety of ways. Very complex term structures for payments can now be built into standardized contracts and traded with low transaction costs, due to computerized analysis of these complex term structures, he wrote.Why We Need Smart Contracts?We can automate many solutions by writing a contract on a Blockchain to make things simple and efficient. lets compare and evaluate how smart contracts are better than traditional contracts. Smart Contracts: Complexity As Per Use CasesThe complexities of contracts depend on the use cases you dream to code on the blockchain. The image below will give you a better clarity on the complexities of the smart contracts.With contextualized smart contracts not only the companies will get automated, but also a decentralizedautonomous government could be formed. Lets understand how smart contracts work with help of use case.Smart Contracts Use Case: Healthcare IndustryPatient Data Management:When it comes t o patient data management, there are two main issues in the healthcare industry:First, each patient is unique, therefore access to complete medical records are essential in order to adapt the treatment and provide personalized careSecond, sharing information among the medical community is a major challengeNow, the above-stated issues can be resolved using smart contracts functionality on blockchains.Smart Contract AdvantagesHereswhat Smart Contracts give you:Blockchain Platforms for Writing Smart ContractsWhile Ethereum is the most popular platform for writing contracts, it is not the only one. The following are some of the other platforms used for writing smart contracts:Bitcoins: Bitcoin uses Script that has limited capabilities when processing documents. The Scripts are specifically designed to process Bitcoin transactions.Hyperledger Fabric:In Fabric, Chaincode is programmatic code deployed on the network, where it is executed and validated by chain validators together during th e consensus process.NXT:Its a public blockchain platform that contains a limited selection of templates for smart contracts. You have to use what is given, you cant write your own code.Side Chains:Side chains enhances Blockchains performance and privacy protections. They also add capabilities like smart contracts, secure handles, and real-world property registry.Tools for Writing Deploying Smart ContractsMist Browser It is a tool to browse and use dApps. It is a separate browser that can be used to browse dApps and interact with them.Truffle Framework Truffle is a popular development framework for Ethereum. It has built-in smart contract compilation, linking, deployment, and binary management.Metamask MetaMask is a bridge that allows one to visit the distributed web of tomorrow in their browser today. It allows users to run Ethereum dApps right in their browser without running a full Ethereum node.Remix Remix is a web browser based IDE that allows users to write Solidity smart cont racts, then deploy and run the smart contract.Programming Languages For Writing Ethereum Smart ContractsSolidity Serpent are two primary languages for writing Ethereum Smart Contracts.Solidity: It is a contract-orientedhigh-level languagewith syntax similar to that of JavaScript and it is designed to target the Ethereum Virtual Machine (EVM).Serpent:Serpent is a high-level language designed for writing Ethereum contracts. It is very similar to Python, but as of September 2017, Solidity is the preferred language of development for Ethereum developers.Though Solidity is currently the most popular language for smart contracts, there are a few upcoming smart contract languages which can become important in the future.Upcoming Programming LanguagesViper:Viper has a Python-like indentation scheme. It focuses on security and language and compiler simplicity.Lisk:Lisk uses javascript as a smart contract language which makes it easier for a developer to code applications.Chain:Chain provide s enterprise-grade blockchain infrastructure with SDKs in popular languages such as Ruby, Java, and NodeJS.Now, since Solidity is most widely used programming language for writing Ethereum Smart Contracts, let me walk you through a contract written in Solidity.Property Transfer Smart ContractProblem: Currently, we use the central authority to transfer the property ownership. This makes it time-consuming and attracts a lot of extra expenses too with an additional burden of document management. Also, since the system is centralized, there is always a possibility of fraudulent.Solution:The plan is to use the technology to make the details of real estate transactions visible to all parties banks, brokers, government officials, buyers and sellerAlright, let me write a Smart Contract for you: pragma solidity ^0.4.11; // We're making this use case for mimicking the real world property transfer // Pre-requisite of this use case is that: // A digital identity is in-place // Govt agrees to put the land records on the public blockchain // Each Development Authority (DA) becomes the defacto owner of the property that exist under their constituency/legislative body // When all the above conditions are met, then DA(owner) can easily attach the respective property to their rightful owner after thorough verification. // we shall be formulating the function around this set assumption. // we're assuming that each DA shall deploy their own smart contract as per their rule and regulation. This whole smart contract is written by considering DA as the owner, who can allot property. // A govt can become a layer on top of these DA. and the Govt can decide, which DA(address) becomes the owner of which contituency. // We can extend this easily. But after going through this smart contract, you shall be able to figure out, how the things might work. contract PropertyTransfer { address public DA; // DA shall be the owner, we shall be initializing this variable's value by the address of the user who's going to deploy it. e.g. let's say DA itself. uint256 public totalNoOfProperty; // total no of properties under a DA at any point of time. they should increase as per the allotment to their respective owner after verification. // Below is the constructor whose code is run only when the contract is created. function PropertyTransfer() { DA = msg.sender; // setting the owner of the contract as DA. }// modifier to check the tx is coming from the DA(owner) or not modifier onlyOwner(){ require(msg.sender == DA); _;} // This structure is kept like this for storing a lot more information than just the name struct Property{ string name; //keeping the map of the property against each address. we shall provide name to the property bool isSold; // we're keeping the count as well for each address } mapping(address = mapping(uint256=Property)) public propertiesOwner; // we shall have the properties mapped against each address by its name and it's individual count. mapping(address = uint256) individualCountOfPropertyPerOwner; // how many property does a particular person hold event PropertyAlloted(address indexed _verifiedOwner, uint256 indexed _totalNoOfPropertyCurrently, string _nameOfProperty, string _msg); event PropertyTransferred(address indexed _from, address indexed _to, string _propertyName, string _msg); // this shall give us the exact property count which any address own at any point of time function getPropertyCountOfAnyAddress(address _ownerAddress) constant returns (uint256){ uint count=0; for(uint i =0; iindividualCountOfPropertyPerOwner[_ownerAddress];i++){ if(propertiesOwner[_ownerAddress][i].isSold != true) count++; } return count; } // this function shall be called by DA only after verification function allotProperty(address _verifiedOwner, string _propertyName) onlyOwner { propertiesOwner[_verifiedOwner][individualCountOfPropertyPerOwner[_verifiedOwner]++].name = _propertyName; totalNoOfProperty++; PropertyAlloted(_verifiedOwner,individualCountOfPropertyPerOwner[_verifiedOwner], _propertyName, property allotted successfully); } // check whether the owner have the said property or not. if yes, return the index function isOwner(address _checkOwnerAddress, string _propertyName) constant returns (uint){ uint i ; bool flag ; for(i=0 ; iindividualCountOfPropertyPerOwner[_checkOwnerAddress]; i++){ if(propertiesOwner[_checkOwnerAddress][i].isSold == true){ break; } flag = stringsEqual(propertiesOwner[_checkOwnerAddress][i].name,_propertyName); if(flag == true){ break; } } if(flag == true){ return i; } else { return 999999999; // We're expecting that no individual shall be owning this much properties }} // functionality to check the equality of two strings in Solidity function stringsEqual (string a1, string a2) constant returns (bool){ return sha3(a1) == sha3(a2)? true:false; } // transfer the property to the new owner // todo : change from to msg.sender function transferProperty (address _to, string _propertyName) returns (bool , uint ) { uint256 checkOwner = isOwner(msg.sender, _propertyName); bool flag; if(checkOwner != 999999999 propertiesOwner[msg.sender][checkOwner].isSold == false){ // step 1 . remove the property from the current owner and decrase the counter. // step 2 . assign the property to the new owner and increase the counter propertiesOwner[msg.sender][checkOwner].isSold = true; propertiesOwner[msg.sender][checkOwner].name = Sold;// really nice finding. we can't put empty string propertiesOwner[_to][individualCountOfPropertyPerOwner[_to]++].name = _propertyName; flag = true; PropertyTransferred(msg.sender , _to, _propertyName, Owner has been changed. ); } else { flag = false; PropertyTransferred(msg.sender , _to, _propertyName, Owner doesn't own the property. );} return (flag, checkOwner); }} So, youve just programmed a way to transfer property on a decentralized network. How Cool is that!!You can see that the potential for [smart contracts] to alter aspects of society is of significant magnitude.With that, I conclude thisSmart Contractblog. I hope you enjoyed reading this blog and found it informative.Got a question for us? Please mention it in the comments section and we will get back to you at the earliest.If you wish to learn Smart Contracts, build a career in the domain of Blockchain and gain expertise in Ethereum programming, get enrolled in live-onlineEdureka BlockchainCertification Traininghere, that comes with 24*7 support to guide you throughout your learning period.Recommended blogs for you Blockchain Tutorial A Beginners Guide to Blockchain Technology Read Article How to write your first Smart Contract? Read Article Ethereum Private Network Create your own Ethereum Blockchain! Read Article What is Blockchain? Step-by-Step Guide for Beginners Read Article Wha t is Blockchain Technology? How Blockchain Works Read Article Defining Blockchain Technology Read Article Blockchain Mining- All You Need To Know Read Article Solidity Tutorial Solidity Programming For Beginners Read Article Blockchain Security: Is Blockchain Really Secure? Read Article How to learn Blockchain? Advantages, Learning path and Future Read Article Truffle Ethereum Tutorial Developing Ethereum DApps with Truffle Read Article Hyperledger vs Ethereum Which Blockchain Platform Will Benefit Your Business? Read Article Everything You Need to Know about Blockchain Architecture Read Article What is Hyperledger An Industrial Approach to Blockchain Read Article Ethereum Upgrades: All you need to know about Ethereums Istanbul Read Article What Is Ethereum? A Platform To Decentralize The World Read Article Blockchain Applications That Are Changing The World Read Article How to Become a Blockchain Developer? Types, Roles and Skills Read Article Hyperledger Fabric A Platform Fo r Business Solutions Read Article Bitcoin Blockchain Explained : Understanding Bitcoin and Blockchain Read Article Comments 1 Comment Trending Courses in Blockchain Blockchain and Ethereum Certification Trainin ...17k Enrolled LearnersWeekendLive Class Reviews 5 (6750)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.