Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useSimulateContract with BigInt argument throws "TypeError: Do not know how to serialize a BigInt" #2833

Closed
1 task done
actuallymentor opened this issue Oct 8, 2024 · 4 comments
Labels
needs reproduction Misc: Needs Reproduction

Comments

@actuallymentor
Copy link

Check existing issues

Viem Version

2.21.18

Current Behavior

const burn_amount = BigInt( Math.floor( burn_amount_float * 10 ** decimals ) )
const call = { abi, address, functionName: 'burn', args: [ burn_amount ] }
const { data: sim_result, error: sim_error } = useSimulateContract( call )

Throws with:

VM258 chunk-VZ7REHMU.js:124 Uncaught TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at hashKey (VM258 chunk-VZ7REHMU.js:124:15)
    at hashQueryKeyByOptions (VM258 chunk-VZ7REHMU.js:121:10)
    at _a8.defaultQueryOptions (VM258 chunk-VZ7REHMU.js:1823:36)
    at _a8.getQueryState (VM258 chunk-VZ7REHMU.js:1676:26)
    at useBaseQuery (VM258 chunk-VZ7REHMU.js:2997:35)
    at useQuery (VM258 chunk-VZ7REHMU.js:3056:10)
    at useQuery2 (VM263 chunk-MEVJJSAC.js:4414:18)
    at useSimulateContract (VM263 chunk-MEVJJSAC.js:5045:10)

Somewhere in the source JSON.stringify is used, but that built-in method does not support the native BigInt. This is a known issue and the reason for libraries like safe-stable-stringify (14m weekly downloads 😬).

Expected Behavior

Should succeed.

Steps To Reproduce

Run the cod above.

Link to Minimal Reproducible Example

https://too_little_bandwidth_sorry.fyi

Anything else?

No response

@jxom jxom added the needs reproduction Misc: Needs Reproduction label Oct 8, 2024
Copy link
Contributor

github-actions bot commented Oct 8, 2024

Hello @actuallymentor.

Please provide a minimal reproduction using StackBlitz, TypeScript Playground (for type issues), or a separate minimal GitHub repository.

Minimal reproductions are required as they save us a lot of time reproducing your config/environment and issue, and allow us to help you faster.

Once a minimal reproduction is added, a team member will confirm it works, then re-open the issue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 8, 2024
@actuallymentor
Copy link
Author

Too busy. The issue source is clear and contained. Apologies.

@jxom
Copy link
Member

jxom commented Oct 8, 2024

Your stack trace sources useSimulateContract, which doesn’t exist in Viem. Best to raise this in Wagmi with a minimal reproducible example.

Copy link
Contributor

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Viem version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction Misc: Needs Reproduction
Projects
None yet
Development

No branches or pull requests

2 participants