12

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" }',
Mike Purvis
  • 251
  • 1
  • 6

3 Answers3

12

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"

Mike Purvis
  • 251
  • 1
  • 6
  • 2
    Awesome! Another solution is to create the sub account with the current as master and then change CONTRACT_NAME in config.js – mattdlockyer Jun 02 '20 at 15:02
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.

Felix Niemeyer
  • 189
  • 1
  • 6
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.