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

Reference Image

Here is the code for the form

<!DOCTYPE html>
<html lang="en">
    <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>

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


    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></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');

        $("#button").click(function() {
            MemUsage.setVal($("#cpu").val(), $("#ram").val());



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.


1 Answer 1


While you can try a web automation tool, this will be slow and often brittle.

A better approach would be use npm and a small script which loads web3js and the text file. Then you can parse the text file and submit the transactions via methods of web3js

The code under "Usage" should get you started: https://github.com/ethereum/web3.js/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.