> For the complete documentation index, see [llms.txt](https://envida-protocol.gitbook.io/envida/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://envida-protocol.gitbook.io/envida/api-recipes/bag.md).

# Bag

## Register

#### Description:

This function register a bag transaction.

#### Steps:

1. Call the bag/register endpoint with the following request body:

* seed: the seed of the account that will pay for the transaction.
* class\_id: the new class identifier that the bag will manage.
* metadata: additional information about the bag.

#### Example Input:

```
{
    "seed": "//Alice",
    "class_id": 100000,
    "metadata": {
        "userdata": "somedata"
    }
}
```

#### Expected Output:

```
{
    "who": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
    "class_id": 100000
}
```

* who: the account address that paid for the transaction.&#x20;
* class\_id: the class identifier managed by the bag.

## Create

#### Description:

This function creates a bag transaction.

#### Previous Steps:

1. [Create an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#create)
2. [Fund an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#fund)
3. [Register bag](#register)

#### Steps:

1. Call the bag/create endpoint with the following request body:

* seed: the seed of the account that will pay for the transaction.
* class\_id: the class identifier that the bag manages.
* owners: array of account addresses that will be associated with the bag.
* shares: the amount of share held by the corresponding owners.

#### Example Input:

```
{
    "seed": "//Alice",
    "class_id": 100000,
    "owners": ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"],
    "shares": [1]
}
```

#### Expected Output:

```
{
    "bag": "5EYCAe5jLQkbmk7kHzj7VNqTGExAEDCjwnnzSh1UEC9N9PgP",
    "class_id": 100000,
    "asset_id": 0,
    "owners": [
        "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
    ]
}
```

* owners: array of account addresses associated with the bag.
* bag: the bag account.
* class\_id: the class identifier that the bag manages.
* asset\_id: the asset identifier that the bag manages.

## Deposit

#### Description:

This function creates a new deposit to the bag account.

#### Previous Steps:

1. [Create an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#create)
2. [Fund an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#fund)
3. [Create a class](broken://pages/U0RjrSPg2emUTyyTlAs1#create-class)
4. [Create an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#create)
5. [Mint an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#mint)
6. [Register bag](#register)
7. [Create a bag](#create)

#### Steps:

1. Call the bag/deposit endpoint with the following request body:

* seed: the seed of the account that will pay for the transaction.&#x20;
* bag: the bag account where the deposit will be made.&#x20;
* class\_ids: an array of the class identifiers that will be part of the transaction.
* asset\_ids: an array of asset\_ids arrays that will be related to each class\_id.
* amounts: an array of amount arrays that will be related to each asset\_id.

#### Example Input:

```
{
    "seed": "//Alice",
    "bag": "5EYCAe5jLQkbmk7kHzj7VNqTGExAEDCjwnnzSh1UEC9N9PgP",
    "class_ids": [1],
    "asset_ids": [[0,1]],
    "amounts": [[100,200]]
}
```

#### Expected Output:

```
{
    "bag": "5EYCAe5jLQkbmk7kHzj7VNqTGExAEDCjwnnzSh1UEC9N9PgP",
    "who": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
}
```

* who: the account address that paid for the transaction.
* bag: the bag account.

## Sweep

#### Description:

This function sweep the deposits made on an bag account to a given account.

#### Previous Steps:

1. [Create an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#create)
2. [Fund an account](broken://pages/PkADXmgJ4GV5VuHSeUDi#fund)
3. [Create a class](broken://pages/U0RjrSPg2emUTyyTlAs1#create-class)
4. [Create an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#create)
5. [Mint an asset](broken://pages/U0RjrSPg2emUTyyTlAs1#mint)
6. [Register bag](#register)
7. [Create an bag](#create)
8. [Bag deposit](#deposit)

#### Steps:

1. Call the bag/sweep endpoint with the following request body:

* seed: the seed of the account that will pay for the transaction.
* bag: the bag account where the deposit were made.
* to: the receiver account address.

#### Example Input:

```
{
    "seed": "//Alice",
    "to": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
    "bag": "5EYCAe5jLQkbmk7kHzj7VNqTGExAEDCjwnnzSh1UEC9N9PgP"
}
```

#### Expected Output:

```
{
    "bag": "5EYCAe5jLQkbmk7kHzj7VNqTGExAEDCjwnnzSh1UEC9N9PgP",
    "who": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
    "to": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
}
```

* who: the account address that paid for the transaction.&#x20;
* to: the receiver account address.
* bag: the bag account.
