Getting "Cannot deserialize the contract state" when calling Rust init function
Asked Answered
F

3

11

I've been able to run near dev-deploy using near-shell for a Rust contract, and then call a function "new" with near call my-account new '{"param1": "foo"}'

However, this does not work when I deploy the same contract to my preferred account created with NEAR Wallet.

The error is:

Smart contract panicked: panicked at 'Cannot deserialize the contract state.: Custom { kind: InvalidInput, error: "Unexpected length of input" }',
Felonious answered 20/3, 2020 at 0:50 Comment(0)
F
11

Turns out there is a common problem in the blockchain world when updating a contract at the same account/address. The solution here was to delete and remake the account. I used near-shell to delete it, then Wallet to recreate it.

On the command line:

near delete my-account another-account-getting-the-tokens

Then created the account again by visiting: https://wallet.nearprotocol.com/create/

This cleared the state and I was able to redeploy the contract and run the init function "new"

Felonious answered 20/3, 2020 at 0:54 Comment(1)
Awesome! Another solution is to create the sub account with the current as master and then change CONTRACT_NAME in config.jsInvalidity
L
2

I stumbled accross the same error in 2021: Cannot deserialize the contract state after making changes to the contract, which has lead me to this stackoverflow question.

I was publishing the contract on testnet by running yarn dev which calls near dev-deploy.

The solution for me was to generate a new dev-user which can be achieved with passing -f as an argument:

near dev-deploy -f path/to/contract.wasm

You can find this by running dev-deploy --help:

-f, --init, --force Create new account for deploy (even if there is one already available). default: false

Hope this helps some.

Levis answered 11/10, 2021 at 19:23 Comment(0)
R
0

According to the document from NEAR: https://docs.near.org/docs/concepts/account#:~:text=Each%20NEAR%20account%20can%20only%20hold%201%20smart%20contract Each NEAR account can only hold one contract. So you cannot make any update on the existing one. There are some solutions you can try:

  • Delete your testnet account then create a new one with the same name as Mike's answer.
  • Directly create a new account or a sub-account and deploy the updated contract to the newly created one.
Renatarenate answered 16/1, 2022 at 5:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.