0

There is a code for a simple conversion (Farenheit to Celcius) in HTML. I am working to recreate the same thing in Solidity. I would need some pointers in making it work. The solidity Code is as follows: enter image description here

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>  
<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>

Koda
  • 78
  • 1
  • 2
  • 8
  • And what's wrong with this exactly? – Jack Bashford Dec 20 '18 at 22:33
  • In Solidity, it does not work. So, I am asking for the correct format in a Solidity blockchain – Koda Dec 20 '18 at 22:47
  • 1
    This question doesn't make any sense. Solidity runs in a blockchain. It does not have access to a DOM (which DOM would it access?). Please look at the answer from @St3C for a good suggestion. – Mathyn Dec 21 '18 at 15:26

1 Answers1

2

Solidity runs the code on the blockchain, this code I do not think makes sense. I think what you need to do is write the logic in the smart contract and then call it from HTML interface. You need web3 to let the interface talk with the smart contract.

contract TemperatureSolution{

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

}

I hope I understand you correctly.

Doc_failure
  • 94
  • 1
  • 8
  • 1
    Thank you for the input @St3C. My intention is to write the solution in Solidity. So, if you know the syntax or logic, that will help. On the other hand, what is the method for calling the solution(smart-contract) from an HTML app/site ? That is when it is correctly written in Solidity – Koda Dec 21 '18 at 18:05
  • the logic of he smart contract should be the one that i wrote in the previous answer. To call that function from you html page you need to use web3. to do that you need to import web3 as a dependencies, use web3 to set the provider and then call the function. This is the link of another answer where is explained how to use web3: https://stackoverflow.com/questions/48184969/calling-smart-contracts-methods-using-web3-ethereum – Doc_failure Dec 24 '18 at 07:49