Skip to main content

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
1 vote
1 answer
876 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, ...
0 votes
1 answer
389 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....
1 vote
1 answer
755 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 ...
0 votes
1 answer
2k 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 ...
2 votes
1 answer
415 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 ...
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....
1 vote
1 answer
379 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, ...
1 vote
2 answers
92 views

ethers.toBigInt(...).eq is not a function

I’m using ethers v6 and comparing the converted numbers, but I’m facing this error: TypeError: ethers.toBigInt(...).eq is not a function
2 votes
2 answers
590 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 ...
0 votes
0 answers
31 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: [ { ...
25 votes
4 answers
64k 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
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....
2 votes
1 answer
183 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 ...
0 votes
1 answer
523 views

What is `ContractTransaction`?

I have a function in my smart contract: function provideLiquidity(address inputToken, uint256 amount) external override onlyValidAddress(inputToken) whenNotPaused ...
1 vote
0 answers
20 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, {...
0 votes
1 answer
57 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 ...
0 votes
1 answer
38 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=...
1 vote
1 answer
1k 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 ...
2 votes
1 answer
311 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 { ...
2 votes
1 answer
189 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 { ...
0 votes
2 answers
237 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(...
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 ...
1 vote
1 answer
561 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, ...
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 ...
0 votes
1 answer
95 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(...
1 vote
1 answer
136 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 ...
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-...
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....
1 vote
1 answer
40 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, ...
1 vote
0 answers
94 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 ...
0 votes
0 answers
43 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 = "...
10 votes
8 answers
18k 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"...
0 votes
1 answer
170 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 ...
0 votes
2 answers
159 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 ...
0 votes
2 answers
404 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
0 answers
41 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: "...
1 vote
1 answer
114 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 ...
1 vote
2 answers
8k 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)); ...
1 vote
1 answer
43 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: ...
0 votes
1 answer
2k 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 = ...
1 vote
1 answer
161 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 ...
3 votes
2 answers
2k 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 ...
11 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 ...
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 ...
0 votes
1 answer
171 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 ...
0 votes
0 answers
202 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, ...
4 votes
1 answer
24k 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 ...
23 votes
5 answers
63k 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 ...
10 votes
3 answers
13k views

How do I send the entire ether balance from one account to another account?

I'm trying to use web3 to transfer all (or as much as I can) of the balance of an account to another account. Here is the code I have so far: var sender = web3.eth.accounts[0]; var receiver = web3....
0 votes
1 answer
715 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 ...