fbpx

Testing integers in smart contract with Truffle and bn.js (Big Number)

Julien Klepatch

In Solidity smart contract, you might have to deal with huge numbers, especially when doing financial transfers. Don’t forget that we need to specify Ether transfers in Wei, a fundamental unit equals to 1 * 10 ^ -18 Ether, so very quickly even small financial values can lead to big numbers.

Dealing with big numbers can create all sort of problems, like underflow or overflow. That is why Truffle uses a special library to deal with integers (i.e the bn.js (Big Number) library). However, this can be confusing. In this video, I show you how to use this library in Solidity tests.

0 Comments

Leave a Reply

More great articles

Advanced storage

In this video, we will build on the previous "Simple storage" smart contract, and store list of data instead of…

Read Story

Contract Inheritance In Solidity | Episode 6

https://youtu.be/BIHNMvbqr0k In object-orientated programming languages, we have classes and inheritance. In Solidity, we don't have classes but we have contracts.…

Read Story

Introduction To Truffle | Episode 5

https://youtu.be/M-w6dDDhu6w Developing smart contracts and distributed applications is hard. There are a lot of different libraries to use, you often…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]
Arrow-up