question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: block.totalAmount.toFixed is not a function

See original GitHub issue

Some blocks cannot be serialised using fromData in the BlockFactory because they throw TypeError: block.totalAmount.toFixed is not a function. This makes it impossible to use getBlocksForRound for any rounds that include blocks that throw this error.

There are “bad” blocks on both devnet and mainnet. An example of a bad block on devnet is at height 766,787:

{"id":"15986760691378510176","version":0,"timestamp":52310186,"height":766787,"reward":"200000000","transactions":[{"version":1,"network":30,"type":0,"timestamp":52308692,"senderPublicKey":"039c09c66328ebe7569cd49aa441e45c9df96c1d644c7acf33f7bc763709c41c1f","fee":"10000000","amount":"0","vendorFieldHex":"54727565205061737461205765696768742e","expiration":0,"recipientId":"D5KU9KrMYXdkEsRbv4y8hvetGbsJwf9z3P","signature":"304402200ca79a6ebcd29cbf6bea42fa6890e0c7bfd82fd5e7cd327913f966b433b24086022051f127b1349af1ccb49cdc27595844d5228d612ef8c7d57d63dc5b75620c7e64","vendorField":"True Pasta Weight.","id":"3945e67bb5e864d2dd206293f1e778fa2181db5f81c2efc0a89e8fe53e2a2e7c"},{"version":1,"network":30,"type":0,"timestamp":52308443,"senderPublicKey":"02364aaaf17c35f74e397433f988361aee408c5b5314eaad5b815c4f4f7c578b1e","fee":"10000000","amount":"250000000","vendorFieldHex":"54727565205061737461205765696768742e","expiration":0,"recipientId":"DJA2sqCbnmR63sD8doGrXrK3fCiqcA4GUw","signature":"3045022100f3a61a0460abe78a4705904216ac17a7bf50b19d70717624c15b64a94207cbeb022070a7bf3d97a3e690839ce1764413ce890ea233eb7eba202d373a376fc4b551b6","vendorField":"True Pasta Weight.","id":"8e4853ed764bb1853e58fda4a9c507f73b820dd738e4a9b197dafb37a22b6b0f"}],"previousBlock":"17296711371070322453","numberOfTransactions":2,"totalAmount":"250000000","totalFee":"20000000","payloadLength":64,"payloadHash":"53033d24a4f133e47fee3871d82bca12bdf8b58ec4ebf43ac2b7849e78278256","generatorPublicKey":"02d0244d939fad9004cc104f71b46b428d903e4f2988a65f39fdaa1b7482894c9e","blockSignature":"30440220053747c5d02b38c9f8980d771918a5c48c99080a0bba661d3609553ed14c3f0d022063da2ba62e002d91b0f3bdba4e0c822bf0f5ce88b95867192252a2418ec0556f","previousBlockHex":"f00a43599f1b3715"}

TypeError: block.totalAmount.toFixed is not a function
    at Function.serializeHeader (/home/ark/.config/yarn/global/node_modules/@arkecosystem/crypto/dist/blocks/serializer.js:50:47)
    at Function.serialize (/home/ark/.config/yarn/global/node_modules/@arkecosystem/crypto/dist/blocks/serializer.js:28:14)
    at Function.serializeWithTransactions (/home/ark/.config/yarn/global/node_modules/@arkecosystem/crypto/dist/blocks/serializer.js:15:39)
    at Function.serializeWithTransactions (/home/ark/.config/yarn/global/node_modules/@arkecosystem/crypto/dist/blocks/block.js:23:40)
    at Function.fromData (/home/ark/.config/yarn/global/node_modules/@arkecosystem/crypto/dist/blocks/factory.js:37:42)

It appears that block.totalAmount is being returned as a string rather than a BigNumber so there is no toFixed function, so it throws the above error.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
alessiodfcommented, Oct 2, 2019

Yes, all good now. Thanks guys!

1reaction
spkjpcommented, Oct 1, 2019

Yeah, it’s definitely a bug. But it’s clear now why it happens. Thanks for reporting!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix javascript .toFixed is not a Function error
But the problem is that var totalSum = (grandTotal + getShippingCost). toFixed(3); throws an error saying Uncaught TypeError: value. toFixed is ...
Read more >
TypeError: toFixed is not a function in JavaScript | bobbyhadz
The "toFixed is not a function" error occurs when the toFixed() method is called on a value that is not a number ....
Read more >
[Solved]-toFixed is not a function?-node.js - appsloveworld
This is all to do with args[0] having the value of a String . With args[0] as a string: (0.044000000000000004 * args[0]) +...
Read more >
JavaScript: Calculate multiplication and division of two numbers
JavaScript exercises, practice and solution: Write a JavaScript function to calculate multiplication and division of two numbers.
Read more >
tofixed is not a function - Code Examples & Solutions For This ...
toFixed isn't a method of non-numeric variable types. In other words, Low and High can't be fixed because when you get the value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found