Jump to content
Sign in to follow this  

Javascript error

Recommended Posts


I am trying to run the following code. I am getting error while executing the line:

truffle(ganache)> const putAmount = putBalance.c[0]


The error is :




const putAmount = putBalance.c[0]



TypeError: Cannot read property '0' of undefined

at evalmachine.<anonymous>:0:31

at sigintHandlersWrap (vm.js:98:15)


I have uploaded the image of the whole program. I don't have much knowledge of Javascript.

Somebody please guide me how to define the property 'c[0]'.




cant read property 0 of undefined2_error line.jpg

Share this post

Link to post
Share on other sites

The error is caused by an outdated Truffle and inconsistent Solidity version not returning the expected JSON result to putBalance. The tests themselves are not written in JavaScript. You are better off learning the latest versions of Truffle and Solidity .

$ sudo apt-get update
$ sudo apt-get install nodejs
$ sudo apt-get install ethereum
$ sudo apt-get install geth
$ sudo npm install -g truffle

$ mkdir MetaCoin
$ cd MetaCoin
$ truffle unbox metacoin 

//Open a seperate terminal and run
$ cd MetaCoin
$ testrpc

//Back in the original terminal
$ truffle test



Share this post

Link to post
Share on other sites

Hi myfriend-

Thanks a lot for your response.


I got the code from the following link:


Please check the above image, they have not defined 'c[0]'.




My Truffle version:


Truffle version is: truffle(ganache)> truffle version Truffle v5.1.27 (core: 5.1.27) Solidity v0.5.16 (solc-js) Node v8.10.0 Web3.js v1.2.1 truffle(ganache)>

Kindly tell me which version are you talking about?

Kindly guide me which tutorial are you using, what is in your 'test' file?


Hi fiveworlds-

You are right. It was a version problem.


truffle(ganache)> const putAmount = putBalance.toNumber()


Edited by zak100

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.