diff --git a/packages/common/README.md b/packages/common/README.md index 026650825..c3e87bb81 100644 --- a/packages/common/README.md +++ b/packages/common/README.md @@ -447,6 +447,26 @@ const updateContractTransaction: AccountTransaction = { ``` Finally, to actually update the contract on the chain, send the constructed `updateContractTransaction` to the chain using `sendAccountTransaction`. (See [Send Account Transaction](#Send-Account-Transaction) for how to do this) +## Serialize parameters with only the specific type's schema +In the previous section the schema used was assumed to be the schema for an entire module. In some cases one might want to use a schema containing only the specific type of the parameter. + +For this, the function `serializeTypeValue` can used. +``` +const inputParams = serializeTypeValue(userInput, rawTypeSchema); +``` + +For reference, the type schema for parameters can be extracted using the functions `getInitContractParameterSchema` and `getUpdateContractParameterSchema`. + +``` +const rawTypeSchema = getUpdateContractParameterSchema( + rawModuleSchema, + contractName, + receiveFunctionName, + userInput, + schemaVersion +) +``` + # Utility functions ## Generate account alias diff --git a/packages/common/src/serialization.ts b/packages/common/src/serialization.ts index b1b8ef142..b8bb40d78 100644 --- a/packages/common/src/serialization.ts +++ b/packages/common/src/serialization.ts @@ -493,7 +493,8 @@ export function serializeUpdateContractParameters( } /** - * @param value the value that should be serialized. Should correspond to the JSON representation. + * Given a value for a smart contract type, and the raw schema for that type, serialize the value into binary format. + * @param value the value that should be serialized. Should correspond to the JSON representation * @param rawSchema the schema for the type that the given value should be serialized as * @returns serialized buffer of the value */