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 to succeed.
Let's say you deployed a contract with the following method:
fn transfer(coins: u64, asset_id: AssetId, recipient: Identity) {
transfer(recipient, asset_id, coins);
} When calling transfer_coins_to_output with the SDK, you can specify the number of variable outputs:
let address = wallet.address();
let asset_id = contract_id.asset_id(&SubAssetId::zeroed());
// withdraw some tokens to wallet
let response = contract_methods
.transfer(1_000_000, asset_id, address.into())
.with_variable_output_policy(VariableOutputPolicy::Exactly(1))
.call()
.await?; with_variable_output_policy sets the policy regarding variable outputs. You can either set the number of variable outputs yourself by providing VariableOutputPolicy::Exactly(n) or let the SDK estimate it for you with VariableOutputPolicy::EstimateMinimum. A variable output indicates that the amount and the owner may vary based on transaction execution.
Note: that the Sway
lib-stdfunctionmint_to_addresscallstransfer_to_addressunder the hood, so you need to callwith_variable_output_policyin the Rust SDK tests like you would fortransfer_to_address.