Closed jack-wombat closed 1 year ago
Out of the box, BigInt does not have support for JSON serialization.
This can be hijacked, as every time serialization should be done at some time, toJSON
is called.
As BigInt does not implement this method, you can do the following:
// Enables JSON serialization of BigInt type
(BigInt.prototype as any).toJSON = function () {
return this.toString();
};
Import this wherever you are using BigInt and you are good to go.
I expect this to be a huge pain point for future user of ethers v6 which use bigint by default. So it's best to handle in the library. JSON.stringify provides a replacer which can stuff in this logic (mdn doc). i.e. if typeof key is bigint or BigInt, then call toString().
Also, the above workaround only works for BigInt
and not bigint
.
@jack-wombat do you know on what field does the serialization fails
like which fields in the json are bigint ?
@wighawag I didn't know which field it fails. I tried adding console.log in the files under node_modules
, but it doesn't seem to catch up on the updates.
I published a potential fix for it in v0.11.31 let me know if this solve your issue
Describe the bug Hardhat deploy uses JSON.stringify which does not know how to serialize bigint. See https://github.com/GoogleChromeLabs/jsbi/issues/30
I dont have visibility into which fields the pendingTransactions is using bigint. But one solution would be to use a string in place of bigint. In fact, this is the work around I'm using now.
This will become a bigger issue when people migrate to ether-v6 which uses bigint in place of big number.
Stack trace:
Line#543 is when DeploymentsManager is saving the pending txn to file:
To Reproduce Deploy anything with bigint.
Expected behavior Expect it to works
versions
Additional context