Problem with truffle console : Cannot read property ‘call’ of undefined

I have a problem when executing the code


This error introduced: Cannot read property ‘call’ of undefined
This problem is similar to this thread but it does not help on my case.

enter image description here
Thanks for your help!

My code is from this turorial

contract HelloWorld {
address public owner;
mapping (address => uint) balances;
function HelloWorld() {
owner = msg.sender;
balances[owner] = 1000;
function transfer(address _to, uint _value) returns (bool success) {
if (balances[msg.sender] < _value) { return false; } balances[msg.sender] -= _value; balances[_to] += _value; return true; } function getBalance(address _user) constant returns(uint _balance) { return balances[_user]; } }

All topic

Out of gas on truffle test

I am following the tutorial on

I am using Ganache for testing, where i am also deploying the tutorial contract.

  1) TestAdoption "before all" hook: prepare suite:
     Error: VM Exception while processing transaction: out of gas
      at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
      at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
      at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
      at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
      at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
      at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
      at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
      at IncomingMessage. (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
      at endReadableNT (_stream_readable.js:1101:12)

What does this mean?
The tests are simple, the contract doesn’t do much.
Where is the gas limit set?

I started ganache with

ganache-cli -l 500000000

Is there something i am missing?

All topic

Sytax Error and Reference Error: Truffle is not defined

I tried to run the Fibonacci program available at:
Look Deeper into variables through Truffle Debugger

I got following error:

truffle(development)> truffle(development)> migrate
ReferenceError: truffle is not defined
truffle(development)> Using network ‘development’.
Using network ‘development’.

SyntaxError: Unexpected identifier
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInContext (vm.js:284:10)
at Console.interpret (C:UsersHPAppDataRoamingnpmnode_modulestrufflebuildcli.bundled.js:94589:17)
at ReplManager.interpret (C:UsersHPAppDataRoamingnpmnode_modulestrufflebuildcli.bundled.js:95306:18)
at bound (domain.js:396:14)

Can somebody please guide me.


All topic

Truffle migration contract not found – but it’s there!

I have a feeling this is going to be a forehead-slapper, but here goes…

I’m attempting to run Truffle’s “Pet Shop” demo app on AWS. The truffle compile command ran fine, with a few non-fatal warnings but nothing major. It completed with…

Writing artifacts to ./build/contracts

…as expected. But truffle migrate is failing, and it seems to be not seeing the contents of the file successfully created at contracts/Migrations.json.

$ truffle migrate
Using network 'development'.
Error: Could not find built Migrations contract: Unexpected token  in JSON at position 0

However, the file is there, and seems fine. Any idea why this is failing?

Also worth noting: I’ve got two console windows running (both SSH’d into the same AWS EC2 instance), and the second of the two is running testrpc. It is “listening” and does tell me…

Listening on localhost:8545

…when I attempt the migration, but nothing beyond that.

Thanks for any nudge in the right direction!

All topic

Contract state won’t change during Truffle tests

I am trying to test my contracts using the Truffle suite, along with Ganache.

Up until now, I have been testing contract functions which are restricted to view only. Now, when I attempt to make changes to the contract state, I’m finding that the state is not actually being changed between function calls.

Consider the following simple contract:

pragma solidity ^0.4.24;

import "../OrderBook.sol";

contract TestOrderBook {
    uint256 newId;

    function addId() public returns (uint256) {
        return newId;

All I wish to do is increment newId and return its new value.

The code I have written to test this is:

const { getWeb3, getContractInstance, parseSignature } = require("./test_helper");
const web3 = getWeb3();
const getInstance = getContractInstance(web3);

contract('IdManager', (accounts) => {
    let IdManager = getInstance('IdManager');

    it('test newId()', async () => {
        console.log(await IdManager.methods.newId().call());
        console.log(await IdManager.methods.newId().call());
        console.log(await IdManager.methods.newId().call());

The getInstance() call is making use of Web3 v1.0, based off this tutorial.

With the above test, I would expect the output to be:


But, I actually get:


Has anyone come across this issue before?

All topic

Deploying on Rinkeby with Truffle using infura

Continuing on the same if i want to use HDWalletProvider to deploy my contract on specific address . What Should i do. rinkeby: { provider: () => { return new HDWalletProvider(“Mnemnoic”, “”) }, network_id: 4, gas: 7003605, gasPrice: 21, host: “localhost”, from: “0xdc18ee70c6215ac9c81a3f704648b8c8a6ec7201”

I am getting following error :Error encountered, bailing. Network state unknown. Review successful transactions manually. Unknown address – unable to sign transaction for this address: “0xdc18ee70c6215ac9c81a3f704648b8c8a6ec7201”

All topic

What is use of HDWalletProvider in Truffle config?

The sample code here for deploying to Ropsten used HDWalletProvider and a mnemonic in the config, but I am not sure I understand its purpose. Is this just telling it the account that will become the contract owner when you deploy?

var HDWalletProvider = require("truffle-hdwallet-provider");

// 12-word mnemonic
var mnemonic = process.env.NMEMONIC;

module.exports = {
  networks: {
    development: {
      host: "",
      port: 8545,
      network_id: "*" // Match any network id
    ropsten: {
      provider: new HDWalletProvider(mnemonic, ""),
      network_id: 3 // official id of the ropsten network

All topic

What are the downsides of using vyper and truffle together

Recently I read an article Vyper+Truffle and wanted to build a token deployer using vyper contracts.

I was wondering if anyone knew the current downsides of using Vyper and truffle together?

Is it better to simply write and deploy vyper smart contracts and then interact with them from the front-end?

All topic

Deploy Smart Contract to Mainnet using Truffle

I was able to deploy the contract successfully to Kovan with gas limit 350000.

When i set the gas in truffle.js to 500000 for deployment to Mainnet, i get the below error:
Error: Transaction cost exceeds current gas limit. Limit: 5000, got: 500000. Try decreasing supplied gas.

So i decrease the gas to 5000, i got the error below:
Error: Transaction gas is too low. There is not enough gas to cover minimal cost of the transaction (minimal: 498172, got: 5000).

it just won’t deploy the contract, how can the Limit is so much lesser than minimal? how to solve this problem?

All topic