I'm building a Dapp where, whenever a user creates an account, it automatically creates an Ethereum address for the user (I'm exposing the personal module over RPC for now, but it's just for playing purposes). I now want to automatically deploy a contract when a user creates an account, ideally to make that user the only address capable of interacting with that contract.
Following some tutorials (this), I installed solc and changed my code to
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
const solc = require('solc');
var fs = require('fs');
const input = fs.readFileSync('contracts/helloWorld.sol');
const output = solc.compile(input.toString(), 1);
const bytecode = output.contracts['helloWorld'].bytecode;
const abi = JSON.parse(output.contracts[':helloWorld'].interface);
This however, throws an error TypeError: Cannot read property ':helloWorld' of undefined
. After some investigation, I realised the output is returning { errors: [ ':1:1: Error: Expected import directive or contract definition.\npragma solidity ^0.4.11;\n^\n' ] }
Finally, even after seeing this answer, I still can't figure out why. I paste my contract code on Remix IDE and it does not throw any error.
My contract code (the test one I'm using now) is
pragma solidity ^0.4.11;
contract helloWorld {
/* Constructor */
address owner;
function helloWorld() {
owner = msg.sender;
}
function remove() {
if (msg.sender == owner) {
// Suicide and send funds to owner
selfdestruct(owner);
}
}
function greet() constant returns (bytes32, address) {
if (msg.sender == owner) {
bytes32 hello = "hello";
return (hello, msg.sender);
}
}
}
Any help would be much appreciated, been stuck for a while :)