14

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

5

When running your code in the Truffle console, it will ensure that certain defaults have been set:

For each network, if unspecified, transaction options will default to the following values:

  • gas: Gas limit used for deploys. Default is 4712388.
  • gasPrice: Gas price used for deploys. Default is 100000000000 (100 Shannon).
  • from: From address used during migrations. Defaults to the first available account provided by your Ethereum client.

(from http://truffleframework.com/docs/advanced/configuration#networks)

But when you're running in a different environment, such as in a browser, then those defaults will not be available and you'll have to specify them for each transaction. In your case that means not only providing from but also gas.

5

Since your example code uses truffle-contract you can specify the default values for your transactions and contract deployments like this (Conferrence is the name of your contract. I used the truffle default values):

Conferrence.defaults({
  from: account,
  gas: 4712388,
  gasPrice: 100000000000
})

I had the same problem (base fee exceeds gas limit) and browser-solidity gave me a Gas requirement of function xyz.sol:Xyz.doSomething(address) unknown or not constant. Specifying default values helped eventually.

3

You need to increase the amount of gas you're willing to pay for the contract creation. For example:

Conferrence.new({from: account, gas: SOME AMOUNT HERE});

Basically the anticipated cost of the transaction is greater than the amount you are providing by default. So you need to bump up the gas in your call to new.

1

I have the same issue and I believe people are getting confused about what the gas parameter actually means in truffle.js file.

I answered my own question here. Hope it helps.

Truffle contract deployment either exceeds block gas limit or out of gas

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.