简体   繁体   English

如何在智能合约上存储用户输入?

[英]How can I store user input on smart contract?

I am trying to create a smart contract in solidity where I am taking user input from a user which basically is a hash and then I want this hash to be stored on to the smart contract so at the end I could create a function where another user could enter a hash and the program would try to match this hash with the previously stored hash. 我试图牢固地创建一个智能合约,在此我从一个用户那里获取用户输入,该用户输入基本上是一个哈希,然后我希望将此哈希存储到智能合约中,因此最后我可以创建一个函数,让另一个用户使用可以输入一个哈希,程序将尝试将该哈希与以前存储的哈希进行匹配。 However, I am not sure how could I store the user's given input on contract? 但是,我不确定如何存储用户在合同中给定的输入?

In Ethereum smart contracts you have state variables which are stored on the blockchain. 在以太坊智能合约中,您具有状态变量,这些状态变量存储在区块链中。 So to store your hash you can create a bytes32 variable and store your user input hash into it. 因此,要存储您的哈希,可以创建一个bytes32变量并将用户输入的哈希存储到其中。

Example-: 例-:

contract testContract{
   bytes32 public userHashs;

   function userInput(bytes32 _hash)public {
      userHashs = _hash;
   }

}

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

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