Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
8 views

How to convert takerRate to readable value from 1inch API OrderBook?

I use 1inch API to get a list of order limits by the specific token. https://portal.1inch.dev/documentation/orderbook/introduction pair AXL/axlUSDC and I get a response something like that: [ { ...
red_space's user avatar
1 vote
1 answer
473 views

SyntaxError: Cannot convert 0.0 to a BigInt

What, is this? SyntaxError: Cannot convert 0.0 to a BigInt JS being JS. What else should we expect from the creators of NaN === NaN; // -> false ? This is one of the worst error reasons I've ...
carlosN's user avatar
  • 11
0 votes
0 answers
17 views

Why can't the gas be estimated?

I'm trying to use another contract to give my leasingContracts unique IDs, but I can't call the function as the code crashes, and I don't understand why. This is the contract for IDs: // SPDX-License-...
Stefan Han's user avatar
2 votes
1 answer
119 views

ethers.js library version to use to learn Ethereum development

Which version of the Ethers.js library, either v5 or v6, is recommended for me to learn and work with? I'm seeking advice on which version would be more beneficial for my current needs and future ...
Israel Ogunsola's user avatar
1 vote
0 answers
17 views

Can't pass Truffle test with an uint256 array as event property

I have this simple test in truffle: it("should emit the correct Transfer event", async function() { await this.contractNFT.multiSafeMint(accounts[0], "CID/metadata.json", 3, {...
viac92's user avatar
  • 33
1 vote
1 answer
585 views

How to get correct liquidity amount on UniswapV3 for each token(pair) via web3.js?

I'm trying to create a bot that will send me new LPS notifications on Uniswap V3 and in the future more dexes. I want to contain in the message specific data like amount of token and ETH in the pool, ...
RasmonT's user avatar
  • 131
0 votes
1 answer
46 views

How to assert that a BigNumber is included in a list of numbers?

I am trying to assert a uint256 the following way: expect(tokenType).to.be.oneOf([1, 2, 3, 4]); I just want to check that its value is any of the ones on that list, as I am using a ...
Falcon Stakepool's user avatar
0 votes
1 answer
33 views

Invalid BigNumber error when converting number fetched from NextRouter

I'm fetching a listing number for an item listed on a marketplace contract and then formatting it to ethers BigNumber. I'm getting error: invalid BigNumber value (argument="value", value=...
Miles Donald's user avatar
1 vote
1 answer
834 views

How would I safely calcuate a percentage of a BigNumber?

I need to multiple and divide a big number in a safe way - without overlow. It won't have to result in an accurate amount to suit me; namely, if it gets round by some function to remain integer rather ...
Kyell's user avatar
  • 91
2 votes
1 answer
228 views

AssertionError: expected BigNumber { value: "0" } to equal BigNumber { value: "0" }

I have created two basic ERC20 tokens (TokenA and TokenB) and a contract that swaps TokenA with TokenB. Everything seems working but I get the error above when I run the test file. How can BigNumber { ...
Claudio's user avatar
  • 35
2 votes
1 answer
163 views

Test failing unexpectedly

This is code for my unit test scripts, I don't know where I am wrong. const { deployments, ethers, network } = require("hardhat") const { assert, expect } = require("chai") const { ...
Yana Gupta's user avatar
0 votes
1 answer
281 views

Impossible to deals with big number in web3.js transacation :

I can't deals with big number (BN.js) with web3.js I have overflow error or i have execution reverted with BN.js library when I try add liquidity to pancakeswap pool. By using BN.js Without using BN....
max's user avatar
  • 1
3 votes
1 answer
38 views

Issue with sending tokens after performing arithmetic operations

I'm implementing a fundraising contract where a user can create a fundraiser but when creating they must send a rewardingToken (ERC20 token) to the contract and the user also specifies a token which ...
stringRay2014's user avatar
1 vote
1 answer
441 views

Trying to apply a slippage to amountOutMin, stuck with a large number

Probably a silly question. I'm trying to apply a slippage (~17%) to amountOutMin and am stuck with a large number. As you can see here, I multiply amountOutMin by 0.83 several times (I don't know, ...
Ivan's user avatar
  • 149
1 vote
1 answer
365 views

How to find percentage change of two BigNumbers of ether.js?

So I have this for calculating percentage change between two BigNumbers: const percentageChange = (a: BigNumber, b: BigNumber) => b.sub(a).div(a).mul(BigNumber.from('100')) Now the issue is when I ...
jafarlihi's user avatar
  • 111
1 vote
1 answer
2k views

How does comparing BigNumbers with ethers work?

I am using ethers and writing tests and I don't quite understand the ethers.BigNumber.from('some number') method. Could someone please explain how it works, the documentation is not very helpful to ...
Kate Johnson's user avatar
0 votes
1 answer
80 views

Ethers.js BigNumber calculation incorrect

I'm trying to replicate the PancakeswapV2 getAmountOut function in Javascript using ethers.BigNumbers as follows (the code in the comment is ad-verbatum from PancakeswapLibrary) function getTokensOut(...
Peter K.'s user avatar
  • 113
1 vote
1 answer
110 views

Is there "any" advantage in using "hexadecimals" for calculation instead of using 'big numbers"?

I would like to know if there is "any" advantage, like speed of execution for example by using "Hexadecimals" instead of "big numbers"? If so can you please tell the ...
Pro Girl's user avatar
  • 257
0 votes
1 answer
1k views

Set Max Approval use big number

i am want create max approval fot approve token transaction on polygon exchange like this const maxApproval = new BigNumber(2).pow(256).minus(1); i see the documention in https://docs.0x.org/0x-api-...
Fatur Rahman's user avatar
1 vote
1 answer
38 views

Some Addresses Work In Function And Others Don't?

I have the below code running based on a series of wallet addresses placed into an array for arbAgainst. const main = async () => { const { token0Contract, token1Contract, token0, ...
Trent Kennelly's user avatar
1 vote
0 answers
89 views

ERC1155 ID - how to handle BigNumber?

I'm exploring Gnosis conditional tokens (which are adapted ERC1155). The _mint method in ERC1155 requires an id that is uint. Gnosis has a method called getPositionId which converts a keccak256 hash ...
alpo's user avatar
  • 164
0 votes
0 answers
41 views

Weird error with addresses

I'm stuck trying to make a truffle test pass with a code similar to next one: 1 const addr1 = '0x35987A0F9AE77012a514835D6DC88b708bC646D6', 2 addr2 = "...
earizon's user avatar
  • 606
0 votes
1 answer
131 views

UniswapV3 swap DAI/USDT issue

I'm using single swap implementation from this tutorial: Single Swaps (in my hardhat testing environment which is Mainnet fork). tokenIn and tokenOut pair of my example is DAI and USDT. The amountIn ...
Ruarin's user avatar
  • 13
0 votes
2 answers
116 views

Problem with setting msg.value of a transaction

First, let's pay attention that this Dapp is deployed on Polygon test net, so it works with MATIC tokens, and all the calculations should comply with this fact. Within the function below, a string ...
Sina Rahimi's user avatar
0 votes
0 answers
38 views

why not getting hex value and isBigNumber boolean value in timestamp?

Terminal when contract deployed 0xf33fd6e51aad88f6f4ce6ab8827279cfffb92266 has waved A message [ [ '0xf33Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'A message', BigNumber { value: "...
vishal's user avatar
  • 23
1 vote
1 answer
109 views

What is the best practice to use when working with numbers in web3.js when interacting with contracts?

What is the best practice when working with numbers with web3.js when interacting with smart contracts? For instance is best practice when working with numbers when interacting with smart contracts ...
Pro Girl's user avatar
  • 257
1 vote
1 answer
40 views

Extracting various elements/values from BigNumber object

When I execute const uniswapReserves = await uniswapDaiEth.getReserves(); code snippet and call out console.log("uniswapReserves: ", uniswapReserves); it produces the following output: ...
Samboy's user avatar
  • 21
0 votes
1 answer
1k views

Ethers JS BigNumber Errors

I'm trying to pass the following number to the approve() function of a standard ERC20 Token contract: 2^256-1 I read that this should be done using BigNumber, using the following code: const maxInt = ...
Mark55's user avatar
  • 1,011
2 votes
1 answer
1k views

What is the best way to divide BN by a decimal?

I am using ethers npm library to divide BN by a decimal. The account(0x..) has 10.99999 GLD. const {ethers} = require('ethers'); const token = myGoldContract.balanceOf('0x....').toString(); console....
Avinash Kulal's user avatar
1 vote
1 answer
370 views

Invalid BigNumber value error. Arguments="value", value=undefined

so I'm getting this error on my deploy script. I have seen the other questions and have tried their solutions but they are not working for me. So this is my deploy script const { netowrk, network, ...
mahdimaster's user avatar
2 votes
1 answer
2k 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 ...
Inn0vative1's user avatar
0 votes
1 answer
170 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 ...
user98077's user avatar
3 votes
2 answers
2k 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....
MehmedB's user avatar
  • 241
0 votes
2 answers
1k 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....
Cizia's user avatar
  • 263
0 votes
0 answers
187 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, ...
BearGyrllz's user avatar
0 votes
2 answers
209 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(...
Avi Rose's user avatar
4 votes
1 answer
23k 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 ...
David's user avatar
  • 153
0 votes
1 answer
508 views

What is `ContractTransaction`?

I have a function in my smart contract: function provideLiquidity(address inputToken, uint256 amount) external override onlyValidAddress(inputToken) whenNotPaused ...
eth_sign's user avatar
0 votes
1 answer
686 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 ...
millbird's user avatar
2 votes
1 answer
3k 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 ...
Kaki Master Of Time's user avatar
0 votes
1 answer
27 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 ...
Sina Rahimi's 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 ...
ginwei's user avatar
  • 61
1 vote
1 answer
3k 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....
Haren Sarma's user avatar
3 votes
1 answer
4k 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 ...
Ev3rlasting's user avatar
10 votes
5 answers
14k 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 ...
frostpad's user avatar
  • 201
0 votes
1 answer
182 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, ...
Hemant Srivastava's user avatar
25 votes
4 answers
62k 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
LiveWire's user avatar
  • 763
0 votes
1 answer
6k 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....
freezy's user avatar
  • 5
1 vote
1 answer
538 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 ...
MikeG's user avatar
  • 113
1 vote
1 answer
76 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 } = ...
Jonathan Scialpi's user avatar