I am going through the Rust SDK documentation and came upon the Output variable section and I am not sure it is clear after reading that section what the append_variable_outputs is and why it is needed when transferring assets to an address.
It says for a contract to transfer funds to an address successfully
The underlying transaction for such a contract call has to have the appropriate number of variable outputs to succeed.
But what exactly is the variable outputs? How is it related to the funds being transferred? What determines the value that is set? In the example it was 1…but not sure why…
Take a look at this forum post for more information on what variable outputs are.
OutputVariables: This output type indicates that the output’s amount and owner may vary based on transaction execution, but is otherwise identical to a Coin output. An amount of zero after transaction execution indicates that the output is unspendable and can be pruned from the UTXO set.
Whenever you do ANY transfers to an address that determines the value being set. Take a look at this AMM function for adding liquidity. After the user adds liquidity the contract transfers back two tokens.
LP token representing their position in the pool
Either token A or token B that was not used up. Never both.
Since that is two transfers within the test here for adding liquidity the value is set to be 2.