Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" }',
like image 971
Mike Purvis Avatar asked Mar 20 '20 00:03

Mike Purvis


2 Answers

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"

like image 54
Mike Purvis Avatar answered Oct 19 '22 20:10

Mike Purvis


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.

like image 43
Felix Niemeyer Avatar answered Oct 19 '22 19:10

Felix Niemeyer