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
How smart contract work
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...