web3.utils
This package provides utility functions for Ethereum dapps and other web3.js packages.
fromDecimalUnit
web3.utils.fromDecimalUnit(value , decimal)
Convert a value from decimal into non-decimal.
Parameters
value-string: The value.decimal-number: The decimal to convert from.
Returns
BN: a BN.js instance.
Example
web3.utils.fromDecimalUnit('1000', 3).toString();
> "1000000"
web3.utils.fromDecimalUnit('100.123456', 6).toString();
> "100123456"
toDecimalUnit
web3.utils.toDecimalUnit(value , decimal)
value-string: The value.decimal-number: The decimal to convert to.
Returns
string: A string number.
Example
web3.utils.toDecimalUnit('1024', 3);
> "1.024"
web3.utils.toDecimalUnit('1024', 6);
> "0.001024"
fromSatoshis
web3.utils.fromSatoshis(value)
Convert a value from satoshis into bsv.
Parameters
value-string|number: The value.
Returns
BN: a BN.js instance.
Example
web3.utils.fromSatoshis('100000000').toString();
> "1"
web3.utils.fromSatoshis('1000').toString();
> "0.00001"
toSatoshis
web3.utils.toSatoshis(value)
Convert a value from bsv into satoshis.
Parameters
value-string|number: The value.
Returns
number: A float number.
Example
web3.utils.toSatoshis('1').toString();
> "100000000"
web3.utils.toSatoshis('0.01').toString();
> "1000000"
verifyMessage
web3.utils.verifyMessage(message, address, signature)
Verify the signature of a message.
Parameters
message-string: The message to sign.address-string: The address of signer.signature-string: The signature.
Returns
boolean: Whether signature is valid or not.
Example
web3.utils.verifyMessage("","","").toString();
> false