I have a simple smart contract running over a local Ethereum node. It has two functions: one for sending data and another for retrieving it back. I have a text file and want to send data from it to the smart contract to store in the blockchain, something like autofilling a web form. I am running a local ethereum node using geth and attaching it to the web3 provider environment in the remix ide.
Can anyone suggest any methods that will be useful for doing this?
Here is the solidity code
pragma solidity ^0.4.18;
contract MemUsage {
uint cpu;
uint ram;
function setVal(uint _cpu, uint _ram) public {
cpu = _cpu;
ram = _ram;
}
function getVal() public constant returns (uint, uint) {
return (cpu, ram);
}
}
And this solidity code is attached to this form
Here is the code for the form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Memory Usage</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="./node_modules/web3/dist/web3.min.js"></script>
</head>
<body>
<div class="container">
<h1>Memory Usage</h1>
<label for="name" class="col-lg-2 control-label">CPU</label>
<input id="cpu" type="text">
<label for="name" class="col-lg-2 control-label">RAM</label>
<input id="ram" type="text">
<button id="button">Update</button>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script>
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
web3.eth.defaultAccount = web3.eth.accounts[0];
var MyContract = web3.eth.contract([
{
"constant": false,
"inputs": [
{
"name": "_cpu",
"type": "uint256"
},
{
"name": "_ram",
"type": "uint256"
}
],
"name": "setVal",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getVal",
"outputs": [
{
"name": "",
"type": "uint256"
},
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]);
var MemUsage = MyContract.at('0xebbfcf2a927db805000b45ac3c3fd46d5bae3909');
console.log(MemUsage);
$("#button").click(function() {
MemUsage.setVal($("#cpu").val(), $("#ram").val());
});
</script>
</body>
</html>
Now, I have a text file with multiple cpu and ram values. I need to automate the form filling process so that I do not have to manually enter all the values through the form.
Thanks