I have the following code in app.js file of my truffle project.
import { default as Web3} from 'web3';
import { default as contract } from 'truffle-contract'
import conferrence_artifacts from '../../build/contracts/Conferrence.json'
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
// Conferrence is our usuable abstraction, which we'll use through the code below.
var Conferrence = contract(conferrence_artifacts);
Conferrence.setProvider(web3.currentProvider);
var accounts = web3.eth.accounts;
var account = accounts[0];
Conferrence.new({from: account}).then(function(instance){
console.log(instance);
});
As provided in the documentation Truffle add new contract
Note: In the call to Conferrence.new({from: account})... {from: account} was used because I was getting 'invalid address error'
Console Error Log
Error: Error: base fee exceeds gas limit
at runCall (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\lib\runTx.js:111:17)
at C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:3686:9
at replenish (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:881:17)
at iterateeCallback (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:866:17)
at C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:843:16
at C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:3691:13
at apply (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:21:25)
at C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:56:12
at Object.async.eachSeries (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\async-eventemitter\node_modules\async\lib\async.js:130:20)
at VM.AsyncEventEmitter.emit (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\async-eventemitter\lib\AsyncEventEmitter.js:42:9)
at runCall (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\lib\runTx.js:111:17)
at C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:3686:9
at replenish (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:881:17)
at iterateeCallback (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:866:17)
at C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:843:16
at C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:3691:13
at apply (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:21:25)
at C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\ethereumjs-vm\node_modules\async\dist\async.js:56:12
at Object.async.eachSeries (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\async-eventemitter\node_modules\async\lib\async.js:130:20)
at VM.AsyncEventEmitter.emit (C:\Users\Devendra\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\node_modules\async-eventemitter\lib\AsyncEventEmitter.js:42:9)
at Object.InvalidResponse (http://localhost:8080/app.js:8374:16)
at http://localhost:8080/app.js:32995:36
at XMLHttpRequest.request.onreadystatechange (http://localhost:8080/app.js:35321:13)
But this works absolutely fine when executing in truffle console -
truffle(development)> Conferrence.new().then(function(ins){console.log(ins.address)})
0x7e796caed4202ae58bb58afc214f281969f995b2
NVM about the 'Conferrence' typo :p