3

I've tried Truffle several times already and I really appreciate their work, but for some me, I find it to be way too opinionated. It has a structure for building the whole app, including the HTML, CSS, migrations. For me, my client(s) are separate projects and I don't need migrations. I'd rather just separe those concerns and have a minimal tool that does only the Ethereum-related development:

  1. Write an Ethereum contract;

  2. Test it by deploying to a local testnet and calling its methods from a separate JS file;

  3. Deploy it to the testnet/mainnet when it is done.

I'm quite lost trying to extract that minimal usage from the whole Truffle workflow. Is there any tool that does that, in an Unix-philosophy way, does that, only that, and does it well?

2

If you speak Python you might feel more comfortable with Populus. It has migrations as a feature, but it doesn't force you to use them.

  • Populus is very UNIXy, but still, like Truffle, provides a lot of of structure with its default management command. If you don't like that structure you can directly call Populus Python APIs and not go through the command line client. I am doing exactly that. – Mikko Ohtamaa Dec 1 '16 at 10:26
0

The simplest way to compile/deploy a contract I found is by using the web3 library from a node.js script. The following helper function deploys a solidity source code and returns the deployed contract object:

var fs = require("fs");
var Web3 = require("web3");
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

// Receives a solidity source code and the account, compiles/deploy
// the contract and calls the callback with the contract object.
function testDeploy(contractSrc, account, callback){
  var contractCmp = web3.eth.compile.solidity(contractSrc);
  var contractCon = web3.eth.contract(contractCmp.info.abiDefinition);
  contractCon.new({
    data: contractCmp.code,
    from: account,
    gas: 1000000},
    function(err, contract){
      if (!contract.address) return;
      callback(contract);
    });
};

You can then call its methods to test them. Example:

testDeploy(`
  pragma solidity ^0.4.0;
  contract HelloWorld {
    event Print(string out);
    function() {
      Print("Hello, World!");
    }
    function test() constant returns (int) {
      return 7;
    }
  }`,
  web3.eth.accounts[0],
  function(contract){
    contract.test({
      value: 0,
      gas: 200000,
      from: web3.eth.accounts[0]},
      function(err, result){
        console.log(result);
      });
  });

This outputs the bignum 7, as expected.

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.