> 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://buycoins.youngest.dev/wallet.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
