简体   繁体   English

如何在Solidity中构建HTML解决方案

[英]How do I build an HTML solution in Solidity

There is a code for a simple conversion (Farenheit to Celcius) in HTML. 在HTML中有一个用于简单转换(从Farenheit到Celcius)的代码。 I am working to recreate the same thing in Solidity. 我正在努力在Solidity中重新创建同样的东西。 I would need some pointers in making it work. 我需要一些指导使其工作。 The solidity Code is as follows: 坚固性代码如下: 在此处输入图片说明

contract TemperatureSolution{
    uint16 input,

    function convertTemp(uint16 _input) public{
        return (document.getElementById("outputCelcius").innerHTML=(valNum-32)/1.8)
    }
    convertTemp(_input);

}

For reference, the HTML that it is based upon is as follows (this works, but I intend to create it on a blockchain): 作为参考,它所基于的HTML如下(此方法可行,但我打算在区块链上创建它):

<html>  
<body>
    <p>Type a value in the Fahrenheit field to convert the value to Celsius:</p>
    <p>
      <label>Fahrenheit</label>
      <input id="inputFahrenheit" type="number" placeholder="Fahrenheit" oninput="temperatureConverter(this.value)" onchange="temperatureConverter(this.value)">
</p>
    <p>Celcius: <span id="outputCelcius"></span></p>

    <script>
    function temperatureConverter(valNum) {
  valNum = parseFloat(valNum);
  document.getElementById("outputCelcius").innerHTML=(valNum-32)/1.8;
    }
    </script>
</body>

Solidity runs the code on the blockchain, this code I do not think makes sense. Solidity在区块链上运行代码,我认为这段代码没有道理。 I think what you need to do is write the logic in the smart contract and then call it from HTML interface. 我认为您需要做的是在智能合约中编写逻辑,然后从HTML界面调用它。 You need web3 to let the interface talk with the smart contract. 您需要使用web3来使界面与智能合约通信。

contract TemperatureSolution{ 合同温度解决方案{

function convertTemp(uint16 _input) public{
    return (_input-32)/1.8);
}

} }

I hope I understand you correctly. 我希望我能正确理解你。

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

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