Use utxo data directly in sway contracts

Hi. I’m new to buildings contracts on utxo based blockchains. It can have a lot of benefits as we can interpretate each fungible assets as unique. However i cannot find any good example in fuel how to deal with utxos in sway.

As i am building a credit protocol. I would like to specifically know if depositor utxo amount is still available in the pool, or if has been transacted (so i would like to find the transaction trail). Is that possible for a contract to use as input data?

Hey Carlos :slight_smile:

When funds are sent from a user to a smart contract, the funds change from a UTXO into a more traditional “account” model. So Pools don’t actually custody any UTXOs.

Does that answer the question?

Hi David. Thanks.

Thank you for the answer. It makes the use of fuel much more confusing. Do you have some documentation about this process?

Hey @carlos :slight_smile: take a look at our AMM example in our sway applications repo and you can see exactly what @david is talking about.

The storage of user deposits is defined as

deposits: StorageMap<(Identity, ContractId), u64> = StorageMap {}

which is the “account” model part he refers to

Within the deposit function you can see how users balances (the deposits mapping) are being updated as the user sends funds to the smart contract.