I'm trying to create and deploy a smart contract through NodeJS using web3, but it is not working as I get a "web3.eth.contract.new is not a function". Here is my code:
var web3 = require('ethereum.js');
var solc = require('solc');
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101/'));
var input = 'contract Hello{ string h = "hello"; function g() constant returns(string){ return h; } }';
var output = solc.compile(input, 1);
for (var contractName in output.contracts) {
var bc = output.contracts[contractName].bytecode;
var abi = output.contracts[contractName].interface;
var contact = web3.eth.contract.new(abi,{from: web3.eth.accounts[0], data: bc});
if (typeof contact.address !== 'undefined') {
console.log('Contract mined! address: ' + contact.address + ' transactionHash: ' + contact.transactionHash);
}
}
Any idea on how to solve this issue? Thanks in advance.
Best Answer
Here is my deploy script that also handles waiting until the transaction is included in a block: