简体   繁体   English

区块链以太坊中的智能合约

[英]Smart contract in blockchain ethereum

I'm trying to deploy a smart contract using testrpc & truffle.我正在尝试使用 testrpc 和 truffle 部署智能合约。 My smart contract is as simple as HelloWorld.我的智能合约就像 HelloWorld 一样简单。 Contract is successfully deployed with 0xfd52dd6fd4002b86ccbd3ae7c7a3e1a9d16c3648 this address.使用 0xfd52dd6fd4002b86ccbd3ae7c7a3e1a9d16c3648 这个地址成功部署了合约。 The only point that I don't understand is, a contract should involve two parties.我唯一不明白的一点是,合同应该涉及两方。 When I run this command HelloWorld.deployed() , I'm only getting from address.当我运行这个命令HelloWorld.deployed() ,我只能地址获取。 I want to have both parameters ie FROM & TO .我想要两个参数,即FROM & TO My question is how to include TO parameter while signing a contract in ethereum?我的问题是如何在以太坊签订合同时包含TO参数?

A smart contract is not necessarily a contract in the terms you are thinking.智能合约不一定是您所考虑的条款中的合约。 I assume you are imagining a contract in which two parties agree to something and that is the stored on the blockchain as proof?我假设您正在想象一份合同,其中两方同意某事,并且存储在区块链上作为证据?

This is not necessarily the case.情况并非一定如此。

A smart contract is simply a program written in Solidity that lies on the Ethereum blockchain, this program can do whatever you want it to do with as many people as you like.智能合约只是一个用 Solidity 编写的程序,它位于以太坊区块链上,该程序可以为任意数量的人做任何您想做的事情。

ie I could create a 'smart contract' which takes in ether and collects it until a specific date, at which point it will release all collected ether to a specified account.即我可以创建一个“智能合约”,它接收以太币并在特定日期之前收集它,届时它将把所有收集的以太币释放到指定帐户。

This does not have to be 'signed' by anyone, any number of participants can come and deposit ether into this contract until a specific date at which point, no one else can deposit.这不必由任何人“签署”,任何数量的参与者都可以将以太币存入该合约,直到特定日期为止,其他人无法存入。

The essence of the 'contract' is that everyone who participates can see that the ether is guaranteed to be locked until that time, and is guaranteed to release whats collected to that address - this cannot be changed. “合约”的本质是每个参与的人都可以看到以太保证在那个时间之前被锁定,并且保证将收集到的东西释放到那个地址——这是无法改变的。 By interacting with the contract, you are essentially 'signing' to say you agree to the terms of which the contract involves.通过与合同互动,您实质上是在“签署”以表示您同意合同所涉及的条款。

So, in the example of your 'hello world' contract, you can deploy it to the network, at which point anyone who wishes to run that contract can check to see what it does and then run it to display 'hello world'.因此,在您的“hello world”合约示例中,您可以将其部署到网络,此时任何希望运行该合约的人都可以检查它的作用,然后运行它以显示“hello world”。

Therefore, you list a 'from' address to specify where it is from, but a 'to' address is unnecessary as anyone can see/interact with it.因此,您列出了一个“发件人”地址来指定它的来源,但“收件人”地址是不必要的,因为任何人都可以看到它/与之交互。

If you would like to limit the contract for use by some specific people, you must list these addresses on the contract and make sure the contract checks whenever someone calls if they are from the addresses specified if not you can revert which will send a message to the user saying they are not allowed to run that function etc.如果你想限制某些特定的人使用合约,你必须在合约上列出这些地址,并确保合约在有人打电话时检查他们是否来自指定的地址,如果不是你可以恢复,这将发送消息给用户说他们不允许运行该功能等。

ContractName.deployed() should give contract instance, then you could call .address on that to get address. ContractName.deployed()应该给出合约实例,然后你可以调用.address来获取地址。 It looks like that's what the guy is doing.看起来这就是这家伙正在做的事情。 I think he doesn't follow that the contract itself has an address, signed by his wallet.我认为他并没有认为合同本身有一个地址,由他的钱包签名。

A smart contract isn't just a contract between 2 parties, it is a verifiable piece of code on the ethereum blockchain that can be mined.智能合约不仅仅是两方之间的合约,它还是以太坊区块链上可以被挖掘的一段可验证的代码。 It has an address, and you are broadcasting it from your wallet.它有一个地址,你正在从你的钱包中广播它。 The address you are calling "from" address is the address of the contract you deployed.您调用“来自”地址的地址是您部署的合约的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM