Adding contract owned assets as inputs to transactions

Hello Fuel team!
Let’s say I have a following function:

pub fn checkAssetOwnership(checked_asset: AssetId) -> bool {
    let num_inputs = input_count().as_u64();
    let mut i = 0;
    while i < num_inputs {
        match input_type(i) {
            Input::Coin => {
                let asset_id = input_asset_id(i).unwrap();
                if asset_id == checked_asset {
                    return true;
                }
            },
            _ => {},
        }
        i = i + 1;
    }
    false

Let’s consider that I have another contract which minted an NFT and owns it.
I wish to send a transaction from that contract to another one to check the ownership using the function above (attaching the input). Is there any way of how I can send an Input from a contract address to check the ownership? If it’s not possible, could you please suggest any alternatives (if any) to achieve that.

Thank you!

3 Likes

Hey @Serafim thanks for the question! I’m getting input on the Sway standards team as to how you should go about this.

2 Likes

Please let me know if this answers your question because I have a feeling I’m misunderstanding your question but…

Contracts can utilize std::context::balance_of to retrieve the balance associated with a specific contractid for a given assetid.

For example, you can see how it is implemented in this code snippet: sway/sway-lib-std/src/context.sw at 55140ba8d534a805f9080b7fa4e9ba8fc99e8d31 · FuelLabs/sway · GitHub.

I hope this helps :slight_smile:

2 Likes

Hey @calldelegation! Seems that the answer solves the problem I’ve got, thank you!

For anyone who has the same question as I did, it might be useful to read the following question to understand how balance is stored for contracts and what’s the difference between account balance and contract balance: How to get the balance of an EOA address in sway

1 Like