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

Borsh seems to fail when deserializing numbers in scientific notation like 7e+24 #134

Open
felixniemeyer opened this issue Nov 6, 2022 · 1 comment

Comments

@felixniemeyer
Copy link

Hi there,

I'm trying to call a contract function with a big number in the args that is represented in the scientific format in the serialized string.

...
    "A": {
        "field": 7e+24,
       ...
    }

The contract function execution fails with:

{"index":0,"kind":{"ExecutionError":"Smart contract panicked: panicked at 'Failed to deserialize input from JSON.: Error(\"expected `,` or `}`\", line: 1, column: 135)'

The column 135 is exactly the "e" character in the number "7e+24" and I think borsh can't cope with the scientific notation of numbers.

I'd expect borsh to deserialize "7e+24" into 7000000000000000000000000 just fine.

Maybe this error is also somehow intentional, because I'm trying to deserialize into a u128 and not every number with a scientific notation can be parsed into a u128. But then I'd expect a different error message, telling me that types are incompatible or so.

Hope this helps

@felixniemeyer
Copy link
Author

If anyone stumbles on this issue because they are trying to get numbers from a js web app to a NEAR contract, the solution is to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant