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

Array deserialization #1063

Open
3 of 4 tasks
mohitxskull opened this issue Jan 26, 2023 · 5 comments
Open
3 of 4 tasks

Array deserialization #1063

mohitxskull opened this issue Jan 26, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@mohitxskull
Copy link

Prerequisites

  • I'm using the latest version of near-api-js.
  • I have tried to start with a fresh project and reproduce the defect with minimal code changes.
  • I have read the console error messages carefully (if applicable).

Description

i have an function on a smart contract which accepts an argument Vec<TokenMetadata>
from my node.js backend i am sending an array, and i am getting an errorsaying

ExecutionError: Smart contract panicked: panicked at 'Failed to deserialize input from JSON.: Error("Invalid last symbol 51, offset 29.", line: 1, column: 185)', nft/src/lib.rs:91:1

Reproducible demo

https://github.com/servedbyskull/near-api-js-error

Steps to reproduce

clone the repo
yarn
yarn build
yarn start

Expected behavior

Should run perfectly

Actual behavior

Throwed an error

Your environment

  • NEAR JavaScript API version used: 1.1.0
  • Frontend framework (if applicable):
  • Relevant dependencies (if applicable):

Self-service

  • I'd be willing to fix this bug myself.
@mohitxskull mohitxskull added the bug Something isn't working label Jan 26, 2023
@andy-haynes
Copy link
Collaborator

Thank you for the detailed description and examples @servedbyskull !

The transaction data appears to be serialized properly in near-api-js since I can deserialize the transaction before it's sent to get the original input. I think the next step would be to try this in the JS and Rust CLIs to see if the behavior is any different there - I'd expect the JS CLI to throw the same error but the Rust CLI uses a different serialization wrapper AFAIK.

@mohitxskull
Copy link
Author

mohitxskull commented Jan 27, 2023

Thank you for the detailed description and examples @servedbyskull !

The transaction data appears to be serialized properly in near-api-js since I can deserialize the transaction before it's sent to get the original input. I think the next step would be to try this in the JS and Rust CLIs to see if the behavior is any different there - I'd expect the JS CLI to throw the same error but the Rust CLI uses a different serialization wrapper AFAIK.

err

Tried with JS Cli, same error

err

Tried with Rust Cli, same error

@andy-haynes
Copy link
Collaborator

Looking up that Invalid last symbol text I see various Rust libraries with the same code around this error message (disclaimer: I don't speak Rust or know whether transaction serialization relies on this same logic):

    /// The last non-padding input symbol's encoded 6 bits have nonzero bits that will be discarded.
    /// This is indicative of corrupted or truncated Base64.
    /// Unlike InvalidByte, which reports symbols that aren't in the alphabet, this error is for
    /// symbols that are in the alphabet but represent nonsensical encodings.
    InvalidLastSymbol(usize, u8),

...

            DecodeError::InvalidLastSymbol(index, byte) => {
                write!(f, "Invalid last symbol {}, offset {}.", byte, index)
            }

It's interesting that the "last symbol" byte mentioned in the error in your example code is 51 but in the CLI examples it's 117. I can't seem to get a value other than 51 by changing the parameters in the example repo so I'm not sure what could account for the disparity there.

This isn't an issue specific to near-api-js but I'm not sure where it would be best transferred. I can keep the issue open until I have a better place to put it but in the meantime I would try DevRel Office Hours or Discord - they should know who to escalate your issue to.

@mohitxskull
Copy link
Author

Any update?

@andy-haynes
Copy link
Collaborator

Did you follow up with DevRel or on Discord?

@github-project-automation github-project-automation bot moved this to Backlog 🥶 in DevRel Jun 10, 2024
@thisisjoshford thisisjoshford removed this from DevRel Oct 31, 2024
@github-project-automation github-project-automation bot moved this to NEW❗ in DevTools Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: NEW❗
Development

No branches or pull requests

2 participants