Jump to content

Javascript error


zak100

Recommended Posts

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

Link to comment
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

image.png.27bd2dc08c97d8829b3c31986fec002c.png

image.png.3c193874302a867027df7dd0a445bbb6.png

Link to comment
Share on other sites

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
Link to comment
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
×
×
  • 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.