-
I am getting an overflow from ethers v5 when trying to read a uint256 containing a large value. In my contract I have: uint256 public miningFee; I have set this value to 20000000000000000000 by passing this value as a BigNumber to the constructor The ABI for the function seems like it specifies that the value is uint256 correctly: {
"inputs": [],
"name": "miningFee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}, in the typechain file I have: miningFee(overrides?: CallOverrides): Promise<[BigNumber]>; when I call the function in my test code as: let miningFee = await Contracts.tokens.miningFee(); I get the following error message: eth_call
Contract call: Tokens#miningFee
From: 0x574b8c3df7413c5873f99422db020835712e9770
To: 0x98bf670d4302af087982a22665eb8d6ce93c5a77
/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/logger/src.ts/index.ts:269
const error: any = new Error(message);
^
Error: overflow [ See: https://links.ethers.org/v5-errors-NUMERIC_FAULT-overflow ] (fault="overflow", operation="BigNumber.from", value=20000000000000000000, code=NUMERIC_FAULT, version=bignumber/5.7.0)
at Logger.makeError (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/logger/src.ts/index.ts:269:28)
at Logger.throwError (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/logger/src.ts/index.ts:281:20)
at throwFault (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:356:19)
at Function.BigNumber.from (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:247:17)
at NumberCoder.encode (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/coders/number.ts:25:27)
at /Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19
at Array.forEach (<anonymous>)
at pack (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)
at TupleCoder.encode (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20)
at AbiCoder.encode (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/abi-coder.ts:111:15) {
reason: 'overflow',
code: 'NUMERIC_FAULT',
fault: 'overflow',
operation: 'BigNumber.from',
value: 20000000000000000000
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
That’s because you are passing in a JavaScript number. If you are passing in a value beyond the ieee 754 safe range, you must either pass in a string or an ES2020 BigInt. This is a safety check because if you use large JavaScript numbers there is no way to ensure there wasn’t precision loss. How are you passing this value in? |
Beta Was this translation helpful? Give feedback.
-
this unit test is passing:
here's how the deployment works:
|
Beta Was this translation helpful? Give feedback.
-
I moved some things around to isolate: console.log('enter here...');
let bigMiningFee: BigNumber = BigNumber.from('200000000000000000000');
await Contracts.tokens.connect(Signers.CFO).setMiningFee(bigMiningFee);
console.log('after setMiningFee');
console.log('before crash');
let readMiningFee = await Contracts.tokens.miningFee();
console.log(`readMiningFee = ${readMiningFee.toString()} [$]`); gives: enter here...
eth_chainId
eth_getTransactionReceipt
eth_chainId
eth_gasPrice
eth_getBlockByNumber
eth_chainId
eth_getTransactionCount
eth_chainId
eth_estimateGas
eth_chainId
eth_sendRawTransaction
Contract call: Tokens#setMiningFee
Transaction: 0xa397cf273b4c949239082a2c2d40f49c5ec375d18c753ae48c4f6d90b4becb7a
From: 0x16aac494f71c836034b4e8e8ab09bf45a9c8f68a
To: 0x98bf670d4302af087982a22665eb8d6ce93c5a77
Value: 0 ETH
Gas used: 29881 of 29881
Block #6: 0x81e4a6bc17ca000378a9e6bbc57d9e4f518cffe063a97ed496156a39e6d9e3f4
after setMiningFee
before crash
eth_chainId
eth_call
Contract call: Tokens#miningFee
From: 0x574b8c3df7413c5873f99422db020835712e9770
To: 0x98bf670d4302af087982a22665eb8d6ce93c5a77
readMiningFee = 200000000000000000000 [$]
Deploying Offers with Tokens at 0x98BF670D4302af087982a22665eb8d6cE93C5A77
eth_chainId
eth_getBalance
/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/logger/src.ts/index.ts:269
const error: any = new Error(message);
^
Error: overflow [ See: https://links.ethers.org/v5-errors-NUMERIC_FAULT-overflow ] (fault="overflow", operation="BigNumber.from", value=20000000000000000000, code=NUMERIC_FAULT, version=bignumber/5.7.0)
at Logger.makeError (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/logger/src.ts/index.ts:269:28)
at Logger.throwError (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/logger/src.ts/index.ts:281:20)
at throwFault (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:356:19)
at Function.BigNumber.from (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:247:17)
at NumberCoder.encode (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/coders/number.ts:25:27)
at /Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19
at Array.forEach (<anonymous>)
at pack (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)
at TupleCoder.encode (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20)
at AbiCoder.encode (/Users/rwalters/Documents/GitHub/blockchain/node_modules/@ethersproject/abi/src.ts/abi-coder.ts:111:15) {
reason: 'overflow',
code: 'NUMERIC_FAULT',
fault: 'overflow',
operation: 'BigNumber.from',
value: 20000000000000000000
} |
Beta Was this translation helpful? Give feedback.
-
I think I see the issue now. this part suggests I'm looking in the wrong place:
since the read value prints I was indeed passing a value incorrectly later in the constructor of my "Offers" contract:
thanks for your help |
Beta Was this translation helpful? Give feedback.
That’s because you are passing in a JavaScript number. If you are passing in a value beyond the ieee 754 safe range, you must either pass in a string or an ES2020 BigInt.
This is a safety check because if you use large JavaScript numbers there is no way to ensure there wasn’t precision loss.
How are you passing this value in?