⌘K

Icon SunFilledIcon MoonStars

Icon LinkOutput variables

Sometimes, the contract you call might transfer funds to a specific address, depending on its execution. The underlying transaction for such a contract call has to have the appropriate number of variable outputs Icon Link to succeed.

Let's say you deployed a contract with the following method:

    fn transfer_coins_to_output(coins: u64, asset_id: AssetId, recipient: Address) {
transfer_to_address(recipient, asset_id, coins);
    }

When calling transfer_coins_to_output with the SDK, you can specify the number of variable outputs by chaining append_variable_outputs(amount) to your call. Like this:

let address = wallet.address();
let asset_id = contract_id.asset_id(&Bits256::zeroed());
 
// withdraw some tokens to wallet
let response = contract_methods
    .transfer_coins_to_output(1_000_000, asset_id, address)
    .append_variable_outputs(1)
    .call()
    .await?;

append_variable_outputs effectively appends a given amount of Output::Variables to the transaction's list of outputs. This output type indicates that the amount and the owner may vary based on transaction execution.

Icon InfoCircle

Note: that the Sway lib-std function mint_to_address calls transfer_to_address under the hood, so you need to call append_variable_outputs in the Rust SDK tests like you would for transfer_to_address.