Reputation: 78
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:
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>
Upvotes: 0
Views: 668
Reputation: 94
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.
Upvotes: 2