Questions tagged [bignumber]

Questions about added-precision libraries often used to account for the large granularity of values across the Ethereum platform (such as bn.js, BigDecimal, or Ethers.js's native BigNumber)

Filter by
Sorted by
Tagged with
0
votes
0answers
16 views

How do I use BigNumber values in Hardhat tests?

I'm using Hardhat with TypeScript/Ethers/Chai. I can't find a way to test BigNumber values. For example, expect(someBigNumber).to.be.equal.to.(otherBigNumber) will (understandably) throw an error like ...
0
votes
1answer
18 views

How to set payment amount to be passed in msg.value

I am working on truffle (solc 0.5) and trying to fetch amount in wei from user and send it to another account. Following is my code: contract pay { uint amount; function payment(uint _amount, ...
0
votes
2answers
191 views

How to convert bignumber to normal number using ethers.js?

I am using ethers.js I can't figure out how do you convert a bignumber like 1252500000000000000 to 125.25 -Mike
0
votes
1answer
212 views

How to convert number to BN with web3

I am trying to get the balance of eth from Metamask account, but I get the following error in the browser console: Uncaught Error: [number-to-bn] while converting number "0.322778986" to BN....
1
vote
0answers
61 views

Uniswap WETH_WBTC price is orders of magnitude off when using constant product market maker formula

I am trying to calculate the value of an exchange on Uniswap using Web3js and methods from the Uniswap smart contract. This is the Uniswap contract address for the WETH (Wrapped Ether) : WBTC (Wrapped ...
1
vote
1answer
26 views

Incorrect Product of BigDecimals

My solidity function emits an event with a uint256 of: 5060584000000000000000000 The problem is on the truffle side in my javascript test. Here is the code: const { BN, expectEvent, constants } = ...
0
votes
1answer
391 views

Random BigNumber in ethers.js

I'm looking to generate a random ethers.js BigNumber in a certain range. While this question has answers about random number generation, the answers as of this writing (April 2021) only cover BigInt, ...
0
votes
1answer
41 views

What is a big number, and why are big numbers used?

I noticed that BigNumber is a special data type in ethereum, and you can't do typical arithmetic operations on it that you would a regular uint. What is the big number, and why does ethereum/(solidity?...
0
votes
1answer
46 views

Converting to/from per-second and annualized interest rates with BigNumber.js

In the MakerDao contracts, there are conversions between annualized percentage rates and per-second percentage rates. For example, their Stability Fees documentation gives this example: If the ...
0
votes
0answers
66 views

How to get the square root of a big number as returned by web3.utils.toBN()?

I'm working with big numbers as returned by web3.utils.toBN(). According to the web3 documentation, this function returns a BN.js instance. However, there doesn't seem to be a square root function on ...
0
votes
1answer
194 views

Error in converting ERC20 tokens with decimals to full coins without rounding errors?

How to convert token to full token without having any rounding errors. web3.utils.toBN(6221221111111110001).div(10**18).toFixed() TypeError: num.isZero is not a function at BN.divmod (...
1
vote
1answer
370 views

ethers.BigNumber.toNumber is not a function

const { ethers } = require('ethers'); console.log(ethers.BigNumber.isBigNumber(totalBalance)); Returns true const { ethers } = require('ethers'); console.log(ethers.BigNumber.toNumber(totalBalance)); ...
0
votes
2answers
47 views

Multiply/divide without an overflow

Need to calculate (at least approximately): customerBalance * numerator * collateralBalance / denominator / INITIAL_CUSTOMER_BALANCE / numberOfCustomers without possibility of overflow. How? Here: ...
0
votes
0answers
17 views

Is 2^64 enough for centuries?

I want my smart contract to lock funds for 100 years. Somebody may use it to lock funds for even more time. Will 2^64 "markets" (anyone can create a new consecutively numbered market) be ...
0
votes
0answers
22 views

calculate exchange rate of WBTC TO WETH in big numbers

i want to calculate how much WETH i will get for a given WBTC amount: const amountsEth = kyber .methods .getExpectedRate( addresses.tokens.wbtc, '...
0
votes
1answer
770 views

web3.utils.toWei(web3.utils.fromWei(…))

Is it warranted that web3.utils.toWei(web3.utils.fromWei(x)) is equal in numeric value to x (provided that x is a 256 bit number represented as a string)? If it is not warranted, how to obtain a value ...
0
votes
1answer
200 views

Error: invalid type (arg=“type”, value=“a”) web3.js

I am trying to get the balance of user for specific token type using web3.js. Here is my code block: var tokenContract = new web3.eth.Contract(erc20abi, tokenAddress) tokenContract.methods....
2
votes
1answer
1k views

Error: Returned error: The execution failed due to an exception. @ web3.eth.estimateGas

I am having problem using bignumber.js with web3: const sender = '0xss'; const recipient = '0xxx'; const amount = 1000; // have to use Bignumber for more than 1000 const decimals = 18; const ...
2
votes
1answer
75 views

Check emitted event with BN

I'm currently testing events that include numeric values: const level = new BN(1); truffleAssert.eventEmitted(tx, 'EventName', {level}); As you can see, the level variable is a BN, and holds the ...
2
votes
2answers
710 views

What big number library does ethers.js use?

Logging a value from a contract with ethers.js, gets me this: tokenBalance: v _hex: "0x033b2b2062ddfc98de7fffff" _ethersType: "BigNumber Is this an instance of bn.js, bignumber.js or a custom ...
0
votes
1answer
827 views

Can't log struct member in truffle test

Contract : mapping (bytes32 => MyStruct) public myMapping; struct MyStruct { uint256 myMember; uint256 someOtherMember; } Test (Truffle) This works: let ...
0
votes
3answers
209 views

Error: new BigNumber() not a base 16 number: at L (bignumber.js:3:2876)

I can not find what the problem is, someone can help me Contract pragma solidity ^0.5.9; contract certificarProceso { address public creador; address emisor; string informacion; ...
1
vote
2answers
754 views

How to convert smallest unit of ERC20 with less than 18 decimals to full coins without rounding errors?

I can just use web3's fromWei function for all token that have 18 decimal places but I'm not sure how to convert token to full token without having to worry about rounding errors. For example convert ...
0
votes
1answer
872 views

BigNumber Error: new BigNumber() not a base 16 number:

I'm new to Ethereum and javascript so hope someone can help me with this as none of the other answers on BigNumber help me understand why this won't work for me. I've tried converting the number to a ...
10
votes
3answers
7k views

How to use bignumbers in truffle tests?

I am testing a smartcontract with Truffle V5. All works well if I do not use all decimals. If I set 18 decimals all explodes. The test code is this (from truffle docs): const MetaCoin = artifacts....
1
vote
1answer
674 views

how to deal with large numbers in Ethereum?

I am confused with the use of large numbers in solidity, ethereum. I have some doubts please help me with them. 1) I am not able to represent the value of p using p.toNumber() but can represent it ...
1
vote
1answer
67 views

Issue with Contract function return value data type

I am using a simple contract Contract code contract Bank { address public owner; mapping(address => uint) private customerBalance; event fallbackCalled(address, uint256); event ...
1
vote
2answers
2k views

Contract deployment using web3.eth.contract(abi) with constructor arguments

I'm trying to deploy the following smart contract: pragma solidity ^0.5.00; contract TestContract { address public owner; string public word; constructor(string memory _word) public{ ...
2
votes
1answer
4k views

Error: Please pass numbers as strings or BigNumber objects to avoid precision errors

let result = await instance.joinQuiz({ from: accounts[1], value: web3.utils.toWei(10, "wei") });
0
votes
1answer
179 views

Doubt with ethereum-input-data-decoder when decoding a variable uint256

the input data of the variable uint256 is "22092018" but when using ethereum-input-data-decoder I return "BN: 15118f2". Instead of getting "BN: 15118f2" with the decoder, have the original value of ...
1
vote
1answer
208 views

How to define 2048-bit integers on smart contracts?

As we know solidity supports only 256-bit big integers. But for crypto primitives (sometimes) we need bigger integers, e.g. 2048-bit. Question: how can we define 2048-bit integers on a smart contract ...
0
votes
1answer
54 views

Is there a form of mapping with an even larger space?

I understand from here that the space for mapping() is drawn from a size of 2^256 * 32 bytes storage, which provides a 1 chance in 10^69 of overwrites. If I'm working with contracts on the order of ...
2
votes
1answer
6k views

How can we parse and deal with BigNumber (BN) args in Solidity events?

In the past, web3 events published numeric events like so: BigNumber { s: 1, e: 17, c: [ 1000 ] } } Now with web3.js 1.0, big numbers come down as objects like this: <BN: de0b6b3a7640000> ...
3
votes
2answers
3k views

How to convert big number to normal number?

I am new to testing and I want to know how to convert a big number to a real number. I use bignumber in the following command: console.log(await this.crowdsale.rate()); This is what gets printed in ...
6
votes
7answers
6k views

Error: Number can only safely store up to 53 bits

const result = await myContract.methods.myMethod(1).call(); brings the error from above. There is a simmilar questions here but since I use call gas shouldn't matter. I'm using "web3": "1.0.0-beta.35"...
1
vote
1answer
1k views

WEI to ETHER conversion issue with Web3 and Javascript

So i have a form where the user enters a price for an item in ETHER. I understand the blockchain does not handle floatin point numbers currently, so i am attempting to convert to WEI and store it on ...
1
vote
0answers
321 views

how do you handle token value data type in database?

Ones who do exchange / Investment platforms development, all ERC20 tokens has its atomic unit and only moved by specifying value in its atomic form. for eg: 1 BuritoToken with unit decimals as 18, ...
1
vote
1answer
232 views

how to parse the value returned by truffle? from balanceOf()

My question is nearly identical to: how to parse the value returned by truffle ? Except that when I run: bigNumberValue.toString() i get '[object Promise]' but then if I treat as a promise and ...
0
votes
2answers
1k views

How to store a Big Number?

I need to determine an expiry date for a contract a for this I use the foloowing code as the constructor of the contract : constructor(address _recipient, uint256 duration) public ...
0
votes
1answer
49 views

how do you convert (small) BigNumbers?

i created a variable called startDate using now in a smart contract. when reading it using Contract.startDate() it returns BigNumber { s: 1, e: 9, c: [ 1530272788 ] } how do i convert this to an ...
1
vote
0answers
324 views

How can I configure BigNumber class in Web3 Version 1.0.0?

Prior to version 1.0.0, I could do it like this, for example: web3.BigNumber.config({DECIMAL_PLACES: 100, ROUNDING_MODE: web3.BigNumber.ROUND_DOWN}); At version 1.0.0, it seems that web3.BigNumber ...
0
votes
1answer
822 views

Truffle Test - Solidity: How to access value of Promise object? [object Promise] [BigNumber]

a.getB.call().then(function (f) { console.log(f[1][0]) }); outputs: BigNumber { s: 1, e: 20, c: [ 5000000 ] } How can I access the value in c? How can I save object f to a javascript variable? ...
3
votes
1answer
1k views

How to convert bigNumber array to int array?

I have a smart contract method that return an array of uint256, but when I console.log the result I got this : [ BigNumber { s: 1, e: 1, c: [Array] } ] How can we convert it to array of numbers? ...
3
votes
1answer
1k views

Truffle CMD Bignumber to number; hex to string

A function in my contract when called on the truffle develop command line gives output in BigNumber format. Here is what I wrote on the command line: instance = contract.at('deployed address') ...
1
vote
1answer
720 views

how can i convert this number to arguments?

in this img you seen 570.1777 ext TRANSFER by function i want now how can convert this amount to arguments easy
3
votes
2answers
140 views

Ethereum scalability and user wait time

If I create a new app that will work on Ethereum network, it takes few seconds for a transaction to be confirmed at least once (creating a sub contract for example), so I can keep using other ...
3
votes
1answer
171 views

uint doesn't return big number object if function is not constant?

So, I have a contract deployed which has a simple function which returns a uint. If I make the function constant it returns the correct value set as a BigNumber object, but if I remove the constant ...
18
votes
4answers
32k views

How to convert BigNumber to Number in Truffle framework?

I have written an ERC20 token contract and deployed it in test network using truffle framework. When I check the token balance for an account using web3 it was giving the result in BigNumber when I ...
4
votes
1answer
56 views

Can I use the `e` notation on MyEtherWallet?

I just found out about the existence of the "minification" process. You probably know about it already, but if you don't, it basically means that 1000 = 10^3 = 1E3 . So 1000 minified is 1E3. Or 10'...
1
vote
3answers
586 views

eth.getPastLogs() requires exact match 32 byte value, how to get bignumber to emit?

the API eth.getPastLogs() requires 4 topics to match the log indexing capabilities of the EVM. It appears to require a full 32 byte number for the match to work. i.e. eth.getPastLogs((fromBlock:0, ...