3

Actually, I'm not even sure if what I'm asking is possible.

At the moment, I can run a script in the Geth Console which is creating contract in local. I would like to create a simple interface with 2 inputs and a submit button to beautify the process.

Do you have any ideas about the easiest way to this ?

2

You should have a look on the web3 library, it's a JavaScript library for Ethereum. So you will be able to build a simple web interface in order to compile and deploy contracts.

Please find a simple example (most of the code is extracted from the web3 documentation) :

// Import web3
var Web3 = require('web3');


// create an instance of web3 using the HTTP provider.
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); 


var contractSource = "" + 
    "contract test {\n" +
    "   function multiply(uint a) returns(uint d) {\n" +
    "       return a * 7;\n" +
    "   }\n" +
    "}\n";

// Compile the contract source
var contractCompiled = web3.eth.compile.solidity(contractSource);

// It should return sometihng like that
// contractCompiled  : {
  "test": {
    "code": "0x605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056",
    "info": {
      "source": "contract test {\n\tfunction multiply(uint a) returns(uint d) {\n\t\treturn a * 7;\n\t}\n}\n",
      "language": "Solidity",
      "languageVersion": "0",
      "compilerVersion": "0.8.2",
      "abiDefinition": [
        {
          "constant": false,
          "inputs": [
            {
              "name": "a",
              "type": "uint256"
            }
          ],
          "name": "multiply",
          "outputs": [
            {
              "name": "d",
              "type": "uint256"
            }
          ],
          "type": "function"
        }
      ],
      "userDoc": {
        "methods": {}
      },
      "developerDoc": {
        "methods": {}
      }
    }
  }
}


// Deploy your contract
var contract = web3.eth.contract(contractCompiled.test.info.abiDefinition);
var contractInstance = contract.new();

Hope this is help you to create a simple interface.

Otherwise, I really like Truffle which is an Ethereum framework and provides a powerful command line tool to develop, compile, test and deploy contracts.

1

This should be a comment but it was too long so...sorry.


Web3 is definitely the easiest way to do so today. We at MyEtherWallet.com didn't have the luxury of Web3 back in the day so we are just set up really simply and continue to do things without web3.

We recently threw together a UI to deploy contracts @ https://www.myetherwallet.com/#deploy-contract

You've got your bytecode, gas, and then you select your private key / keystore file in order to generate, sign, and broadcast the transaction. The private key never leaves your machine.

We considered adding compilation from Solidity but decided that Browser Solidity is amazing and gives you all the options and versions you want so why bother.

Once you have the compiled bytecode, actually deploying is quite easy. Estimate the gas, generate the TX using the data provided (the bytecode), sign it, and broadcast it. The code for that page can be seen here: https://github.com/kvhnuke/etherwallet/blob/mercury/app/scripts/controllers/deployContractCtrl.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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