How smart contract work

Smart contract is firstly defined as 'a computerized transaction protocol that executes the terms of a contract' by Nick Szabo.
It translates contractual clauses(collateral, bonding, etc) into code, and embedding them into property (hardware, or software) that can self-enforce them, so as to minimize the need for trusted intermediaries between transacting parties, and the occurence of malicious or accidental exceptions.
Within the blockchain context, smart contracts are scripts stored on the blockchain. (They can be thought of as roughly analogous to stored procedures in relational database management systems.) Since they reside on the blockchain, they have a unique address. We trigger a smart contract by addressing a transaction to it. It then executes independently and automatically in a prescribed manner on every node in the network, according to the data that was included in the triggering trasaction. (This implies that every node in a smart contract-enabled blockchain is running a virtual machine (VM), and that the blockchain network acts as a distributed VM.)
Smart contracts allow us to have general purpose computations occur on the chain. Where they excel however, is when they are tasked with managing data-driven interactions between entities on the network. Let us unpack this statement with an example. Consider a blockchain network where Alice, Bob, and Carol participate, and where digital assets of type X and Y are being traded.Bob deploys a smart contract on the network that defines: (a)a "deposit" function allowing his to deposit units of X into the contract, (b) a "trade" function that sends back 1 unit of X(from the contract's own deposits) for every 5 units of Y it receives, and (c) a "withdraw" function that allows Bob to withdraw all the assets that the contract holds.
Note that the "deposit" and "withdraw" functions are written so that only Bob(via his key) can call them, becuase this is what Bob decided, and also what makes sense for our example; they could have been written so that they can be called successfully by any user on the network.
Bob sends a transaction to that smart contract's address, calling its "deposit" function and moving 3 units of X to the contract. This transaction is recorded on the blockchain. Alice, who owns 12 units of Y, then sends a transaction that moves 10 units of Y to the contract's

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,494评论 0 23
  • 果果: 你害我几乎一夜没有合眼。你试过在如雷的鼾声和幼童的哭闹声中睡去吗?那感觉就好像脑袋上方漂浮着一只愈来愈涨大...
    Queenie1990阅读 1,535评论 0 0
  • 1. 从早起去学校交住宿表一直忙到10点,回宿舍路上恰好碰到一个外国人问路,本着忙完心情好乐意帮助人的态度想帮他,...
    苦菜汤阅读 2,990评论 0 0
  • 出差到上海,拜访客户完,离回去的高铁还早就去外滩拍张美丽的全景。
    带头大哥的哥阅读 1,477评论 0 0

友情链接更多精彩内容