This is a [[3. Conditional Transactions|conditional transaction]] where funds can only be spent by specific users who were granted permission to do so when the transaction was created.
To spend funds from the [[3. Conditional Transactions#Conditional OUT|conditional output]] of such a transaction, another transaction must be created with the required number of valid signatures from wallets that were authorized to sign such transactions.
The **shared funds** mechanism is designed to prevent bridges and staking from uncontrollable infinite emission, thereby enhancing the system's security.
Any user can create such a transaction, allocate funds to its conditional output, and designate specific users who will have the right to sign a spending transaction to withdraw these funds, either fully or partially.
This can be applied to [[Bridge|bridge emission]], [[Stake|staking rewards]] and other cases, where we have to limit funds available for debit.
Commands for create such transaction and debit funds from it are available here:
**[[WALLET SHARED. Node Commands]]**
## Debit Example
There are three transactions.
![[Pasted image 20250515113802.png]]
**Shared funds** initially received a definite amount of funds `SUPPLY VALUE` on its item `IN EMS`, and therefore, these funds can be debited from the `COND OUT (WALLET SHARED)` of this transaction. Also, there is an [[Item|item]] `MINIMAL NUMBER OF VALID SIGNATURES` which defines how signatures are required to debit funds from this transation. In this case - **6**.
Next, the transaction **successful debit** receives a specified amount of funds from the `COND OUT (WALLET SHARED)` to its `COND IN (VALUE)` item. This transfer was successful because the transaction was signed by six wallets with corresponding delegated rights. Then, this `VALUE` will be used to pay for the validator fee via transfer to corresponding `COND OUT (FEE)`, while the rest of the sum will be directed on `OUT (VALUE)`, waiting for debit.
The transaction **failed debit** has the same items, but not enough valid signatures (**4** instead of **6**).
This transfer wil be blocked, and the funds will remain on `COND OUT (WALLET SHARED)` of the **shared funds** transaction.
## Usage Example
Let’s take the following example.
> [!EXAMPLE] Example
> A user has multiple wallets. The main one with a majority of funds and two additional wallets.
To ensure the safety of funds he decides to lock them with a **shared funds** transaction.
First, we need to retrieve public key hashes from the wallets.
`Command:`
```actionscript
cellframe-node-tool wallet pkey show <wallet name>
```
`Examples:`
```actionscript
cellframe-node-tool wallet pkey show main_wallet
0x0E9D0534BD148C2373CC78C5834D08246A52F6D169DEAB99F8D7CCEAF107A1CE
```
```actionscript
cellframe-node-tool wallet pkey show second_wallet
0xF8DA3298DFC838741ABAA8D8AA5056E54D0FC15E8FC0EF3A89290476778FC1D5
```
```actionscript
cellframe-node-tool wallet pkey show third_wallet
0x011FCE96B76FBA54F5EB67AA134A013C3BD52EB88A4132A7F5C1939807F3D5A7
```
Next step is to [[Node Command - WALLET SHARED HOLD|create]] a conditional **shared funds** transaction which locks funds on the [[3. Conditional Transactions#Conditional OUT|conditional OUT]].
`Command syntax:`
```actionscript
wallet shared hold
-net <net_name>
-w <wallet_name>
-token <ticker>
-value <value>
-fee <value>
-signs_minimum <value_int>
-pkey_hashes <hash1[,hash2,...,hashN]>
[-tag "<str>"] -
[-H {hex(default) | base58}]
```
`Options:`
```actionscript
-net - name of the Cellframe Network. The list of networks can be found in the <Config_dir> \ etc \ network folder or received by The Cellframe-Node-CLI using command - net list
-w - wallet for take funds, pay fee and sign tx
-token - ticker of the token
-value - amount of funds being taken for holding
-fee - commission for transaction
-signs_minimum - number of required valid signatures for funds debit tx
-pkey_hashes - owners public key hashes, who can sign a debit tx (minimum - 1)
-tag - additional info about tx (optional)
-H - hash format: HEX or base58 (optional)
```
`Command example:`
```actionscript
cellframe-node-cli wallet shared hold -net raiden -w main_wallet -token tCELL -value 900000.0 -fee 1.0 -signs_minimum 2 -pkey_hashes 0x0E9D0534BD148C2373CC78C5834D08246A52F6D169DEAB99F8D7CCEAF107A1CE,0xF8DA3298DFC838741ABAA8D8AA5056E54D0FC15E8FC0EF3A89290476778FC1D5,0x011FCE96B76FBA54F5EB67AA134A013C3BD52EB88A4132A7F5C1939807F3D5A7
```
`Result:`
```actionscript
status: success
tx_hash: 0x608FD1A636FD6F1C35A454B268115AF939732D0E8F9D6F8B95A35C2014AABC4D
```
Once a transaction is processed, we can check its contents.
Let’s take a look at its [[3. Conditional Transactions#Conditional OUT|conditional OUT]].
```actionscript
cellframe-node-cli tx_history -tx 0x608FD1A636FD6F1C35A454B268115AF939732D0E8F9D6F8B95A35C2014AABC4D -net raiden
```
```actionscript
item type: OUT COND
ts_expires: never
coins: 900000.0
value: 900000000000000000000000
subtype: DAP_CHAIN_TX_OUT_COND_SUBTYPE_WALLET_SHARED
uid: 0x0000000000000007
tsd_size: 114
```
Funds are successfully locked.
Next, let’s [[Node Command - WALLET SHARED TAKE|debit]] some of the funds and initiate a transaction using one of the wallets which were granted permissions previously.
Recipient of the funds will be a wallet that is not allowed to interact with **shared funds** transaction.
`Command syntax:`
```actionscript
wallet shared take
-net <net_name>
-w <wallet_name>
-tx <transaction_hash>
-to_addr <addr1[,addr2,...,addrN]>
-value <value1[,value2,...,valueN]>
-fee <value>
[-H {hex(default) | base58}]
```
`Options:`
```actionscript
-net - name of the Cellframe Network. The list of networks can be found in the <Config_dir> \ etc \ network folder or received by The Cellframe-Node-CLI using command - net list
-w - the name of the wallet which has a right to debit funds
-tx - hash of the shared funds transcaction
-to_addr - recipient addresses, their quantity must match the values specified numbe
-value - value sent to each recipient, must match the addresses number
-fee - commission for transaction
-H - hash format: HEX or base58 (optional)
```
`Command example:`
```actionscript
cellframe-node-cli wallet shared take -net raiden -w second_wallet -tx 0x608FD1A636FD6F1C35A454B268115AF939732D0E8F9D6F8B95A35C2014AABC4D -to_addr jrmnGqeeds4Dp67AZE9LY5uWW5zrbm8ugCYn5BJ6GXFdZiZkDgkAPPPvQkTTZxzjLj3LsabF8Zz96kkcmXZf4phyUskWZYSNW3TpKjqF -value 50000.0 -fee 1.0
```
`Result:`
```actionscript
status: success
tx_hash: 0x075051A67F29290D73192C13685D173C1017A973DC5E0AC7DFDA0AB3CF60AAE9
```
After creating a transaction, it will have only one signature, provided by the creator's wallet.
We need to add remaining signatures to match **`-signs_minimum`** value from `WALLET SHARED HOLD`transaction.
It can be done via the [[Node Command - WALLET SHARED SIGN|WALLET SHARED SIGN command]].
`Command syntax:`
```actionscript
wallet_shared sign
-net <net_name>
-w <wallet_name>
-tx <transaction_hash>
[-H {hex(default) | base58}]
```
`Options:`
```actionscript
-net - name of the Cellframe Network. The list of networks can be found in the <Config_dir> \ etc \ network folder or received by The Cellframe-Node-CLI using command - net list
-w - the name of the signing wallet
-tx - hash of the debit transaction
-H - hash format: HEX or base58 (optional)
```
`Command example:`
```actionscript
cellframe-node-cli wallet shared sign -net raiden -w third_wallet -tx 0x075051A67F29290D73192C13685D173C1017A973DC5E0AC7DFDA0AB3CF60AAE9
```
`Result:`
```actionscript
status: success
tx_hash: 0x61B12392FDD90D9A8247DFC7EDDF85DF18CC372240769EE78DC521BDF3B659AF
```
Once a transaction is processed, tokens are sent to the destination address and the amount of remaining funds on the [[3. Conditional Transactions#Conditional OUT|conditional OUT]] has decreased.
Let’s check that.
`Command:`
```actionscript
cellframe-node-cli tx_history -tx 0x61B12392FDD90D9A8247DFC7EDDF85DF18CC372240769EE78DC521BDF3B659AF -net raiden
```
Take a look at [[Item|items]] **OUT** and **OUT COND**.
```actionscript
item type: OUT
Coins: 50000.0
Value: 50000000000000000000000
Address: jrmnGqeeds4Dp67AZE9LY5uWW5zrbm8ugCYn5BJ6GXFdZiZkDgkAPPPvQkTTZxzjLj3LsabF8Zz96kkcmXZf4phyUskWZYSNW3TpKjqF
item type: OUT COND
ts_expires: never
coins: 850000.0
value: 850000000000000000000000
subtype: DAP_CHAIN_TX_OUT_COND_SUBTYPE_WALLET_SHARED
uid: 0x0000000000000007
tsd_size: 114
```
Coins (value) on the [[3. Conditional Transactions#Conditional OUT|conditional OUT]] of `DAP_CHAIN_TX_OUT_COND_SUBTYPE_WALLET_SHARED` subtype have decreased from **900000** to **850000**.
## Interaction
How to interact with the **shared funds** [[3. Conditional Transactions#Conditional OUT|conditional OUT]]?
In all subsequent transactions debiting transactions, any hash of the previously created transactions that contain conditional `OUT` can be used.
> [!IMPORTANT] Note
> In all subsequent transactions debiting transactions, any hash of the previously created transactions that contain conditional OUT can be used.
Here are two more examples:
1) Debit funds using the hash of the original transaction.
2) Debit funds using the hash of subsequent debit transaction.
### First Example
Creating a transaction to debit funds:
Hash of the original transaction - `0x608FD1A636FD6F1C35A454B268115AF939732D0E8F9D6F8B95A35C2014AABC4D`.
```actionscript
cellframe-node-cli wallet shared take -net raiden -w third_wallet -tx 0x608FD1A636FD6F1C35A454B268115AF939732D0E8F9D6F8B95A35C2014AABC4D -addr_to jrmnGqeeds4Dp67AZE9LY5uWW5zrbm8ugCYn5BJ6GXFdZiZkDgkAPPPvQkTTZxzjLj3LsabF8Zz96kkcmXZf4phyUskWZYSNW3TpKjqF -value 500.0 -fee 1.0
```
`Result:`
```actionscript
status: success
tx_hash: 0xC2C0E5F9BF4BE7D81F4C9E1B9568262B24920DCC100374989AF3C192B8C93AC1
```
`Adding a second sign:`
```actionscript
cellframe-node-cli wallet shared sign -net raiden -w second_wallet -tx 0xC2C0E5F9BF4BE7D81F4C9E1B9568262B24920DCC100374989AF3C192B8C93AC1
```
`Result:`
```actionscript
status: success
tx_hash: 0x0D21733CE3036987F34951AEA59AC47D2D09197DFB2D08723A798B01DC799F9E
```
Relevant transaction OUT's after it is processed:
```actionscript
cellframe-node-cli tx_history -tx 0x0D21733CE3036987F34951AEA59AC47D2D09197DFB2D08723A798B01DC799F9E -net raiden
```
`Result:`
```actionscript
item type: OUT (1)
Coins: 500.0
Value: 500000000000000000000
Address: jrmnGqeeds4Dp67AZE9LY5uWW5zrbm8ugCYn5BJ6GXFdZiZkDgkAPPPvQkTTZxzjLj3LsabF8Zz96kkcmXZf4phyUskWZYSNW3TpKjqF
item type: OUT COND (2)
ts_expires: never
coins: 849500.0
value: 849500000000000000000000
subtype: DAP_CHAIN_TX_OUT_COND_SUBTYPE_WALLET_SHARED
uid: 0x0000000000000007
tsd_size: 114
```
### Second Example
Creating a transaction to debit funds:
Hash of the subsequent transaction - `0x61B12392FDD90D9A8247DFC7EDDF85DF18CC372240769EE78DC521BDF3B659AF`.
```actionscript
cellframe-node-cli shared funds -net raiden -w second_wallet -tx 0x61B12392FDD90D9A8247DFC7EDDF85DF18CC372240769EE78DC521BDF3B659AF -addr_to jrmnGqeeds4Dp67AZE9LY5uWW5zrbm8ugCYn5BJ6GXFdZiZkDgkAPPPvQkTTZxzjLj3LsabF8Zz96kkcmXZf4phyUskWZYSNW3TpKjqF -value 200.0 -fee 1.0
```
`Result:`
```actionscript
status: success
tx_hash: 0x3074E8768F374FA42BA68FC997E683443F5FACC142859032EF91C6CE3753F73F
```
`Adding a second sign:`
```actionscript
cellframe-node-cli shared funds sign -net raiden -w third_wallet -tx 0x3074E8768F374FA42BA68FC997E683443F5FACC142859032EF91C6CE3753F73F
```
`Result:`
```actionscript
status: success
tx_hash: 0xCD944B7E2BED8A7A0501A1DF27C7BB27744911ED8BD720A281EAF77B60749A37
```
Relevant transaction OUTs after it is processed:
```actionscript
cellframe-node-cli tx_history -tx 0xCD944B7E2BED8A7A0501A1DF27C7BB27744911ED8BD720A281EAF77B60749A37 -net raiden
```
`Result:`
```actionscript
item type: OUT (1)
Coins: 200.0
Value: 200000000000000000000
Address: jrmnGqeeds4Dp67AZE9LY5uWW5zrbm8ugCYn5BJ6GXFdZiZkDgkAPPPvQkTTZxzjLj3LsabF8Zz96kkcmXZf4phyUskWZYSNW3TpKjqF
item type: OUT COND (2)
ts_expires: never
coins: 849300.0
value: 849300000000000000000000
subtype: DAP_CHAIN_TX_OUT_COND_SUBTYPE_WALLET_SHARED
uid: 0x0000000000000007
tsd_size: 114
```
As we can see, [[3. Conditional Transactions#Conditional OUT|conditional OUT]] displays correct balance.