Skip to main content

Function Parameters

The optional params subsection contains field definitions for each of the parameters that a function takes. The layout of the field definitions is identical to that of the state field definitions with one addition, the field type can be followed by a question mark to indicate that the parameter is optional.

The schema tool will automatically generate an immutable structure with member variables for proxies to each parameter variable in the params map. It will also generate code to check the presence of each non-optional parameter, and it will also verify the parameter's data type. This checking is done before the function is called. The user will be able to immediately start using the parameter proxy through the structure that is passed to the function.

When this subsection is empty or completely omitted, no structure will be generated or passed to the function.

For example, here is the structure generated for the immutable params for the member function:

type ImmutableMemberParams struct {
proxy wasmtypes.Proxy
}

// address of dividend recipient
func (s ImmutableMemberParams) Address() wasmtypes.ScImmutableAddress {
return wasmtypes.NewScImmutableAddress(s.proxy.Root(ParamAddress))
}

// relative division factor
func (s ImmutableMemberParams) Factor() wasmtypes.ScImmutableUint64 {
return wasmtypes.NewScImmutableUint64(s.proxy.Root(ParamFactor))
}

Note that the schema tool will also generate a mutable version of the structure, suitable for providing the parameters when calling this smart contract function.

In the next section, we will look at the results subsection.