How can I fix "Error happened while deserializing the module" error?

2.2k views Asked by At

Git repo clone link: https://github.com/oserk/NearProtocol-Student-Award.git

Note: You will get the same error when you follow the steps in the "readme" file.

Error name: Error happened while deserializing the module

Error screenshot: errorscreenshot

2

There are 2 answers

1
AfroRick On

Pretty solid chance that this is related to a change in the contract state where you've added/removed fields from the contract struct and this has resulted it in no longer being deserializable because the struct format has changed:

When you create a NEAR contract, state is stored and if you modify the structs (add remove fields and such) you can find yourself in a state where the contract can no longer be deserialized.

Typically this happens when you're trying to deploy a modified contract atop an existing contract. Easy button answer is to blow away the old account (which will remove the state), then add it back and redeploy the contract. There are ways to upgrade a contract as well - but they aren't easy button

We hit it enough that we just put it into the build script:

near delete contractname.myaccount.testnet myaccount.testnet
near create-account contractname.myaccount.testnet --masterAccount myaccount.testnet --initialBalance 20
near deploy --wasmFile target/wasm32-unknown-unknown/release/contractname.wasm --accountId contractname.myaccount.testnet -f
0
Peter Salomonsen On

This happens because the WebAssembly file is using opcodes that are not supported by nearvm. For example emscripten will now by default output webassembly files with sign-ext operations which is not supported by the nearvm wasm validator. In order to mitigate this you can use wasm-opt from binaryen to lower the use of sign-ext operations:

wasm-opt -Oz --signext-lowering contract.wasm -o contract.wasm

Also an issue for this has been created here: https://github.com/near/nearcore/issues/8358