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
0 answers
42 views

Making offer on opensea

Trying to write a script to make offers on opensea but get error: Error: Expected amount to be of type BigNumber, encountered: 1 import Web3 from 'web3' import { OpenSeaPort, Network } from 'opensea-...
user avatar
  • 1
1 vote
1 answer
134 views

Comparing ethers BigNumber does not work

I'm testing the value of a BigNumber returned from a function call to a contract and its not working as expected. I have this const { BigNumber } = require('ethers'); ... const totalSupply = await ...
user avatar
0 votes
1 answer
27 views

Sending big values to wallet

I want to send big value (10000000) for example to other wallet but i have error like this: UnhandledPromiseRejectionWarning: Error: Error: [number-to-bn] while converting number 3.0244e+22 to BN.js ...
user avatar
0 votes
1 answer
415 views

Convert big number to number on hardhat tests

Sorry for the newbie question. There are a lot of solutions but non of them worked for me. I am getting an account's balance with const balance_before = await ethers.provider.getBalance(redeemer....
user avatar
  • 118
0 votes
2 answers
147 views

Property 'BN' does not exist on type 'Utils' web3js

I am trying to convert a web3 BigNumber into an ethersjs BigNumber but I can't create a Web3 BigNumber variable. I am typing import Web3 from "web3"; const web3 = new Web3; let BN = web3....
user avatar
  • 103
0 votes
0 answers
186 views

Passing values to BigNumber

I am trying to pass a value from state into a function call (submitCourse below) that supposedly takes a BigNumber (I say supposedly because that's what the first error said, but on the contract it's ...
user avatar
0 votes
0 answers
56 views

How can I format gas price with eth-hooks?

import { useGasPrice } from 'eth-hooks' //using version 2.3.16 const NETWORK = { name: "mainnet", color: "#ff8b9e", chainId: 1, rpcUrl: REACT_APP_INFURA_ID, ...
user avatar
0 votes
1 answer
39 views

How do I access a BigNumer in a transaction object?

I am struggling to simply access the BigNumber Object from the gasPrice in Javascript. Currently, I am storing the whole transaction to a variable called result, and want to be able to console.log(...
user avatar
2 votes
1 answer
4k views

Ethers.js - Error: invalid BigNumber string

I am trying to approve a larger amount of erc-20 tokens (it has 18 decimals). await token.connect(signer).approve(contractAddress, BigNumber.from((1000*(tenToPowerOf18Digits)).toString())) : If I try ...
user avatar
  • 77
0 votes
1 answer
148 views

What is `ContractTransaction`?

I have a function in my smart contract: function provideLiquidity(address inputToken, uint256 amount) external override onlyValidAddress(inputToken) whenNotPaused ...
user avatar
  • 21
0 votes
1 answer
237 views

Modifying receive function to take ether input instead of Wei

I am building a Shared Wallet contract as a project. As I have started working on the front end in react web app I have encountered the problem that javascript cannot store large numbers. I could not ...
user avatar
1 vote
1 answer
593 views

how to convert "0.5" number knowing decimals to a valid bignumber

I am trying to create a transaction where the users sends "0.5" USDT token to a smart contract. My issue is that i can't convert "0.5" to a BigNumber in order to pass it in the ...
user avatar
0 votes
1 answer
23 views

Construction function [closed]

My construction function accepts three arguments, one of which has to be a specific amount written in Wei. Whenever I try to compile and migrate my contract an error shows up notifying me that number ...
user avatar
2 votes
1 answer
3k views

Error encoding arguments: invalid BigNumber string after deploying to Remix

I wanna create a system allowing a company to save several data in the contract, and at the same time many companies can save data in this system. So I create the mapping of struct, and there's array ...
user avatar
  • 51
1 vote
1 answer
2k views

while converting number 0.001 to BN.js instance, error: Value must be an integer, hex string, BN or BigNumber instance

I want to transfer 0.001 token and I cannot use web3.utils.toWei(0.001) as the smart contract has 12 decimal instead of 18 decimal. How can I correct it ? var decimals = 12; var amount = web3....
user avatar
2 votes
1 answer
1k views

What is the logics behind Q64.96 number?

Checking the math behind uniswap v3 and I constantly seeing the term: Q64.96 in sqrtRatioX96 I am just wondering if this is a naming convention in smart contract world to describe the format of the ...
user avatar
7 votes
5 answers
6k 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 ...
user avatar
  • 171
0 votes
1 answer
134 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, ...
user avatar
15 votes
2 answers
22k 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
user avatar
  • 463
0 votes
1 answer
4k 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....
user avatar
  • 5
1 vote
1 answer
328 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 ...
user avatar
  • 113
1 vote
1 answer
38 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 } = ...
user avatar
1 vote
2 answers
3k 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, ...
user avatar
0 votes
1 answer
155 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?...
user avatar
0 votes
1 answer
102 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 ...
user avatar
  • 107
1 vote
0 answers
206 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 ...
user avatar
  • 113
0 votes
1 answer
772 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 (...
user avatar
1 vote
1 answer
2k 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)); ...
user avatar
  • 563
0 votes
2 answers
204 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: ...
user avatar
  • 1,334
0 votes
0 answers
21 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 ...
user avatar
  • 1,334
0 votes
1 answer
1k 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 ...
user avatar
  • 1,334
0 votes
1 answer
546 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....
user avatar
2 votes
1 answer
3k 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 ...
user avatar
  • 143
2 votes
1 answer
119 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 ...
user avatar
  • 350
2 votes
2 answers
1k 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 ...
user avatar
1 vote
1 answer
1k 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 ...
user avatar
0 votes
1 answer
266 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; ...
user avatar
1 vote
2 answers
1k 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 ...
user avatar
0 votes
1 answer
1k 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 ...
user avatar
  • 1
14 votes
3 answers
13k 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....
user avatar
  • 143
1 vote
1 answer
2k 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 ...
user avatar
1 vote
1 answer
121 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 ...
user avatar
2 votes
2 answers
4k 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{ ...
user avatar
2 votes
1 answer
6k 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") });
user avatar
0 votes
1 answer
242 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 ...
user avatar
1 vote
1 answer
479 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 ...
user avatar
  • 1,947
0 votes
1 answer
80 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 ...
user avatar
3 votes
1 answer
12k 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> ...
user avatar
  • 356
4 votes
2 answers
7k 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 ...
user avatar
  • 317
10 votes
7 answers
13k 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"...
user avatar
  • 323