{"record":{"id":"df5552d921590a28","repo":"linera-io/linera-protocol","slug":"failed-to-deserialize-instantiation-argument-argu","errorCode":null,"errorMessage":"Failed to deserialize instantiation argument {argument:?}","messagePattern":"Failed to deserialize instantiation argument (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-sdk/src/contract/mod.rs","lineNumber":51,"sourceCode":"macro_rules! contract {\n    ($contract:ident) => {\n        #[doc(hidden)]\n        static mut CONTRACT: Option<$contract> = None;\n\n        /// Export the contract interface.\n        $crate::export_contract!($contract with_types_in $crate::contract::wit);\n\n        /// Mark the contract type to be exported.\n        impl $crate::contract::wit::exports::linera::app::contract_entrypoints::Guest\n            for $contract\n        {\n            fn instantiate(argument: Vec<u8>) {\n                use $crate::util::BlockingWait as _;\n                $crate::contract::run_async_entrypoint::<$contract, _, _>(\n                    unsafe { &mut CONTRACT },\n                    move |contract| {\n                        let argument = $crate::serde_json::from_slice(&argument)\n                            .unwrap_or_else(|_| panic!(\"Failed to deserialize instantiation argument {argument:?}\"));\n\n                        contract.instantiate(argument).blocking_wait()\n                    },\n                )\n            }\n\n            fn execute_operation(operation: Vec<u8>) -> Vec<u8> {\n                use $crate::util::BlockingWait as _;\n                $crate::contract::run_async_entrypoint::<$contract, _, _>(\n                    unsafe { &mut CONTRACT },\n                    move |contract| {\n                        let operation = <$contract as $crate::abi::ContractAbi>::deserialize_operation(operation)\n                            .expect(\"Failed to deserialize `Operation` in execute_operation\");\n\n                        let response = contract.execute_operation(operation).blocking_wait();\n\n                        <$contract as $crate::abi::ContractAbi>::serialize_response(response)\n                            .expect(\"Failed to serialize `Response` in execute_operation\")","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-sdk/src/contract/mod.rs#L33-L69","documentation":"The linera-sdk contract entrypoint macro deserializes the raw instantiate argument bytes with serde_json into the application's generated InstantiateArgument type. If the bytes are not valid JSON for that exact type, the generated entrypoint panics. This happens inside the contract's Wasm/EVM sandbox, so the failure aborts the operation and is reported back through block execution.","triggerScenarios":"Creating/publishing a contract with an instantiation argument that does not match the app's declared type: passing BCS or hex-encoded bytes instead of JSON, wrong field names, wrong field types, or a JSON shape from an older version of the app's ABI.","commonSituations":"Using --json-argument with a hand-written JSON whose keys don't match the struct; the app changed InstantiateArgument between versions but callers still send the old shape; passing [] or a bare number where a struct/unit object {} is expected; copy-pasting arguments between different example apps.","solutions":["Serialize the argument with serde_json from the app's exact InstantiateArgument type (in the app's tests) and pass that JSON verbatim","Check every field name and type against the app's struct definition (serde renames included)","For a unit-like argument pass {} or omit the argument entirely per the app's docs","If the app was recently changed, re-publish and re-create with arguments matching the new ABI"],"exampleFix":"// before (caller passes mismatched JSON)\nlet argument = br\"[1, 2, 3]\"; // expected struct { name: String, value: u64 }\n\n// after\n#[derive(Serialize)]\nstruct Args { name: String, value: u64 }\nlet argument = serde_json::to_vec(&Args { name: \"test\".into(), value: 1 })?;","handlingStrategy":"validation","validationCode":"// Client-side, before publishing/creating the contract:\nlet bytes = serde_json::to_vec(&argument)?;\nserde_json::from_slice::<app::InstantiationArgument>(&bytes)\n    .expect(\"argument must round-trip as the app's InstantiateArgument type\");\n// now safe to pass `bytes`","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always serialize arguments from the app's own types instead of hand-writing JSON","Keep an integration test that instantiates the app with the same argument producers used in production","When the app's argument type changes, version the app and update callers together"],"tags":["sdk","serde","json","smart-contract","instantiate","user-applications"],"backgroundTag":"json-deserialization-failed","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}