This repository has been archived by the owner on Mar 5, 2025. It is now read-only.
[types][web3-utils] Use bn.js directly for class BN instead of wrapper #2350
Labels
Types
Incorrect or missing types
Expected behavior
Let
BN
denote the class as exported fromweb3-utils
, notbn.js
.Assigning results of
BN
methods, likeadd()
, to variables of typeBN
should work.Actual behavior
Doesn't compile, throws typescript errors.
Steps to reproduce the behavior with error logs
The code
gives error
So right now I do arithmetics with
a.add(toBN(1)) as BN
hacks.Now I could instead do
import BN = require('bn.js');
but then I get another error when passing thoseBN
s into, e.g.,web3.utils.soliditySha3
:Background
The web3-utils type declarations internally first do
(which in itself is confusing, because
bn.js
is usually imported asBN
andBigNumber
is used forbignumber.js
) and then declares and exports a wrapper classWhy is that? Why doesn't web3 just use
bn.js
directly?This whole
BN
situation is a bit confusing, see also #2171Versions
Tested with node
v11.9.0
web3 version1.0.0-beta.43
and typescript3.3.1
in a trufflev5.0.2
project.The text was updated successfully, but these errors were encountered: