> For the complete documentation index, see [llms.txt](https://buycoins.youngest.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://buycoins.youngest.dev/wallet.md).

# Wallet

To get started with using the Wallet class, import it from the `buycoins` package:

{% code title="wallet.py" %}

```python
from buycoins import Wallet
```

{% endcode %}

You can use the class directly using `Wallet().method_name` or instantiate the class into a variable and use:

```python
wallet = Wallet()
wallet.method_name(**args)
```

### buy\_crypto(currency, coin\_amount)

This method is used to buy an amount `coin_amount` of the supplied `currency`.

#### Example:

{% code title="wallet.py" %}

```python
from buycoins import Wallet

wallet = Wallet()

buy_bitcoin = wallet.buy_crypto(currency="bitcoin", coin_amount=0.05)

print(buy_bitcoin)
```

{% endcode %}

This printed response:

```python
{
    "id": "QnV5Y29pbnNQcmljZS05NjNmZTExOS02ZGVhLTRlMDItYTc3NC1lZjViYjk3YWZiNGE=",
    "cryptocurrency": "bitcoin",
    "status": "processing",
    "totalCoinAmount": 0.05,
    "side": "buy",
}
```

### sell\_ crypto(currency, coin\_amount)

This method sells an amount `coin_amount` of the supplied`currency` at the current BuyCoin's price.

#### Example:

{% code title="wallet.py" %}

```python
from buycoins import Wallet

wallet = Wallet()

sell_bitcoin = wallet.sell_crypto(currency="bitcoin", coin_amount=0.05)

print(sell_bitcoin)
```

{% endcode %}

The printed response:

```python
{
    "id": "QnV5Y29pbnNQcmljZS05NjNmZTExOS02ZGVhLTRlMDItYTc3NC1lZjViYjk3YWZiNGE=",
    "cryptocurrency": "bitcoin",
    "status": "processing",
    "totalCoinAmount": 0.05,
    "side": "sell",
}
```

### get\_network\_fee(currency, coin\_amount)

This method calculates and returns the network fee for an amount `coin_amount` of the supplied `currency`.

#### Example:

{% code title="wallet.py" %}

```python
from buycoins import Wallet

wallet = Wallet()

network_fee = wallet.get_network_fee(currency="bitcoin", coin_amount=0.01)

print(network_fee)
```

{% endcode %}

The response printed:

```python
{
    "estimatedFee": 0.00044,
    "total": 0.01044,
}
```

### create\_address(currency)

This method creates a wallet address for the given `currency`.

#### Example:

{% code title="wallet.py" %}

```python
from buycoins import Wallet

wallet = Wallet()

usd_coin_address = wallet.create_address(currency="usd_coin")

print(usd_coin_address)
```

{% endcode %}

The printed response:

```python
{
    "cryptocurrency": "usd_coin", 
    "address": "0x3856c5511ac5344eb85d439e338ae0f1b5dbe34a",
}
```

### send\_crypto(currency, coin\_amount, address)

This method sends an amount`coin_amount`of the specified `currency` to the supplied address.

#### Example

{% code title="wallet.py" %}

```python
from buycoins import Wallet

wallet = Wallet()

send_usd_coin = wallet.send_crypto(currency="usd_coin", coin_amount=20, address="0x3856c5511ac5344eb85d439e338ae0f1b5dbe34a")

print(send_usd_coin)
```

{% endcode %}

The printed response:

```python
{
    "id": "QnV5Y29pbnNQ=",
    "address": "0x3856c5511ac5344eb85d439e338ae0f1b5dbe34a",
    "amount": 20,
    "cryptocurrency": "usd_coin",
    "fee": 1.25,
    "status": "processing",
    "transaction": {
        "txhash": "hybuojpkllmjvvcdersxkjijmkllbvdsabl",
        "id": "QnV5Y29pbnNQ=",
    }
}
```

{% hint style="danger" %}
Sending cryptocurrencies via the API is currently not supported. You need to contact [BuyCoin's support](mailto:support@buycoins.africa) to lift the restriction.
{% endhint %}

### get\_balances()

This gets all cryptocurrency balance available to the user.

#### Example:

```python
from buycoins import Wallet

wallet = Wallet()

balances = wallet.get_balances()

print(balances)
```

The printed response:

```python
[
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'usd_tether',
    'confirmedBalance': '10.0'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'naira_token',
    'confirmedBalance': '5357872.49'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'bitcoin',
    'confirmedBalance': '10.0'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'ethereum',
    'confirmedBalance': '20.0033'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'litecoin',
    'confirmedBalance': '640.0'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'usd_coin',
    'confirmedBalance': '309.75'
  }
]

```

### Errors

Appropriate error responses are sent in the event of an unsuccessful request or insufficient data to complete or execute requests.
