Jump to content

Javascript error

Featured Replies

Hi,

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 :

Quote

 

evalmachine.<anonymous>:0

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]'.

 

Zulfi.

 

cant read property 0 of undefined2_error line.jpg

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

image.png.27bd2dc08c97d8829b3c31986fec002c.png

image.png.3c193874302a867027df7dd0a445bbb6.png

  • Author

Hi myfriend-

Thanks a lot for your response.

 

I got the code from the following link:

https://github.com/Bdragon93/reentrancy-acttack

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

 

 

 

My Truffle version:

Quote

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?

Zulfi.

Hi fiveworlds-

You are right. It was a version problem.

Correct:

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


Zulfi.

Edited by zak100

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.