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)
103 questions
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
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:
[
{
...
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 ...
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 ...
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, {...
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
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
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....
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, ...
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 ...
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-...
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 = "...
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
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
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 = ...
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....
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, ...
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 ...
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....
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....
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,
...
0
votes
2
answers
236
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(...
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 ...
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
...
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 ...
3
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 ...
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 ...
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 ...
2
votes
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....
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 ...
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 ...
0
votes
1
answer
184
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, ...
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
1
vote
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....
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 ...
1
vote
1
answer
80
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 } = ...