Metadata-Version: 2.1
Name: cdp-sdk
Version: 0.10.3
Summary: CDP Python SDK
Author-email: John Peterson <john.peterson@coinbase.com>
License: Apache-2.0 License
        
        Copyright 2024 Coinbase
            
        Licensed under the Apache License, Version 2.0 (the "License");
        you may not use this file except in compliance with the License.
        You may obtain a copy of the License at
        
          http://www.apache.org/licenses/LICENSE-2.0
        
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
Project-URL: Homepage, https://docs.cdp.coinbase.com/cdp-sdk/docs/welcome
Keywords: coinbase,sdk,crypto,cdp
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: aiohappyeyeballs==2.4.0
Requires-Dist: aiohttp==3.10.5
Requires-Dist: aiosignal==1.3.1
Requires-Dist: annotated-types==0.7.0
Requires-Dist: asn1crypto==1.5.1
Requires-Dist: async-timeout==4.0.3
Requires-Dist: attrs==24.2.0
Requires-Dist: bip-utils==2.9.3
Requires-Dist: bitarray==2.9.2
Requires-Dist: cbor2==5.6.4
Requires-Dist: certifi==2024.8.30
Requires-Dist: cffi==1.17.1
Requires-Dist: charset-normalizer==3.3.2
Requires-Dist: ckzg==2.0.1
Requires-Dist: coincurve==20.0.0
Requires-Dist: crcmod==1.7
Requires-Dist: cryptography==43.0.1
Requires-Dist: cytoolz==0.12.3
Requires-Dist: ecdsa==0.19.0
Requires-Dist: ed25519-blake2b==1.4.1
Requires-Dist: eth-account==0.13.3
Requires-Dist: eth-hash==0.7.0
Requires-Dist: eth-keyfile==0.8.1
Requires-Dist: eth-keys==0.5.1
Requires-Dist: eth-rlp==2.1.0
Requires-Dist: eth-typing==5.0.0
Requires-Dist: eth-utils==5.0.0
Requires-Dist: eth-abi==5.1.0
Requires-Dist: frozenlist==1.4.1
Requires-Dist: hexbytes==1.2.1
Requires-Dist: idna==3.10
Requires-Dist: multidict==6.1.0
Requires-Dist: parsimonious==0.10.0
Requires-Dist: py-sr25519-bindings==0.2.0
Requires-Dist: pycparser==2.22
Requires-Dist: pycryptodome==3.20.0
Requires-Dist: pydantic==2.9.2
Requires-Dist: pydantic-core==2.23.4
Requires-Dist: PyJWT==2.9.0
Requires-Dist: PyNaCl==1.5.0
Requires-Dist: python-dateutil==2.9.0.post0
Requires-Dist: pyunormalize==16.0.0
Requires-Dist: regex==2024.9.11
Requires-Dist: requests==2.32.3
Requires-Dist: rlp==4.0.1
Requires-Dist: six==1.16.0
Requires-Dist: toolz==0.12.1
Requires-Dist: types-requests==2.32.0.20240914
Requires-Dist: typing-extensions==4.12.2
Requires-Dist: urllib3==2.2.3
Requires-Dist: web3==7.2.0
Requires-Dist: websockets==13.0.1
Requires-Dist: yarl==1.11.1
Provides-Extra: dev
Requires-Dist: astroid==3.2.4; extra == "dev"
Requires-Dist: autopep8==1.5.5; extra == "dev"
Requires-Dist: coverage==7.6.1; extra == "dev"
Requires-Dist: isort==5.13.2; extra == "dev"
Requires-Dist: mccabe==0.6.1; extra == "dev"
Requires-Dist: mypy==1.11.2; extra == "dev"
Requires-Dist: mypy-extensions==1.0.0; extra == "dev"
Requires-Dist: pycodestyle==2.6.0; extra == "dev"
Requires-Dist: pydocstyle==6.3.0; extra == "dev"
Requires-Dist: pyflakes==2.2.0; extra == "dev"
Requires-Dist: pylint==3.2.7; extra == "dev"
Requires-Dist: pytest==8.3.3; extra == "dev"
Requires-Dist: pytest-cov==5.0.0; extra == "dev"
Requires-Dist: ruff==0.6.5; extra == "dev"
Requires-Dist: types-requests==2.32.0.20240914; extra == "dev"
Requires-Dist: yapf==0.40.2; extra == "dev"
Requires-Dist: jedi==0.17.2; extra == "dev"
Requires-Dist: pygls==1.3.1; extra == "dev"
Requires-Dist: python-language-server==0.36.2; extra == "dev"
Requires-Dist: pytoolconfig==1.3.1; extra == "dev"
Requires-Dist: rope==1.13.0; extra == "dev"
Requires-Dist: ruff-lsp==0.0.56; extra == "dev"
Requires-Dist: pluggy==1.5.0; extra == "dev"
Requires-Dist: parso==0.7.1; extra == "dev"
Requires-Dist: lsprotocol==2023.0.1; extra == "dev"
Requires-Dist: sphinx==8.0.2; extra == "dev"
Requires-Dist: sphinx-autobuild==2024.9.19; extra == "dev"
Requires-Dist: sphinxcontrib-napoleon==0.7; extra == "dev"
Requires-Dist: sphinx-autodoc-typehints==2.4.4; extra == "dev"
Requires-Dist: myst-parser==4.0.0; extra == "dev"

# CDP Python SDK

The CDP Python SDK enables the simple integration of crypto into your app.
By calling Coinbase's CDP APIs, the SDK allows you to provision crypto wallets,
send crypto into/out of those wallets, track wallet balances, and trade crypto from
one asset into another.

**CDP SDK v0 is a pre-alpha release, which means that the APIs and SDK methods are subject to change. We will continuously release updates to support new capabilities and improve the developer experience.**

## Documentation

- [CDP API Documentation](https://docs.cdp.coinbase.com/platform-apis/docs/welcome)
- [CDP SDK Python Documentation](https://coinbase.github.io/cdp-sdk-python/)

## Requirements

- Python 3.10+

### Checking Python Version

Before using the SDK, ensure that you have the correct version of Python installed. The SDK requires Python 3.10 or higher. You can check your Python version by running the following code:

```bash
python --version
pip --version
```

If you need to upgrade your Python version, you can download and install the latest version of Python from the [official Python website](https://www.python.org/downloads/).
For `pip`, refer to the [official pip documentation](https://pip.pypa.io/en/stable/installation/) for installation instructions.

## Installation

```bash
pip install cdp-sdk
```

### Starting a Python REPL

To start a Python REPL:

```bash
python
```

## Creating a Wallet

To start, [create a CDP API key](https://portal.cdp.coinbase.com/access/api). Then, initialize the CDP SDK by passing your API key name and API key's private key via the `configure` method:

```python
from cdp import *

api_key_name = "Copy your API key name here."

api_key_private_key = "Copy your API key's private key here."

Cdp.configure(api_key_name, api_key_private_key)

print("CDP SDK has been successfully configured with CDP API key.")
```

Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your API key,
downloaded from the CDP portal.

```python
Cdp.configure_from_json("~/Downloads/cdp_api_key.json")

print("CDP SDK has been successfully configured from JSON file.")
```

This will allow you to authenticate with the Platform APIs.

If you are using a CDP Server-Signer to manage your private keys, enable it with

```python
Cdp.use_server_signer = True
```

Now create a wallet. Wallets are created with a single default address.

```python
# Create a wallet with one address by default.
wallet1 = Wallet.create()

print(f"Wallet successfully created: {wallet1}")
```

Wallets come with a single default address, accessible via `default_address`:

```python
# A wallet has a default address.
address = wallet1.default_address
```

## Funding a Wallet

Wallets do not have funds on them to start. For Base Sepolia testnet, we provide a `faucet` method to fund your wallet with
testnet ETH. You are allowed one faucet claim per 24-hour window.

```python
# Fund the wallet with a faucet transaction.
faucet_tx = wallet1.faucet()

# Wait for the faucet transaction to complete.
faucet_tx.wait()

print(f"Faucet transaction successfully completed: {faucet_tx}")
```

## Transferring Funds

See [Transfers](https://docs.cdp.coinbase.com/wallets/docs/transfers) for more information.

Now that your faucet transaction has successfully completed, you can send the funds in your wallet to another wallet.
The code below creates another wallet, and uses the `transfer` function to send testnet ETH from the first wallet to
the second:

```python
# Create a new wallet wallet2 to transfer funds to.
wallet2 = Wallet.create()

print(f"Wallet successfully created: {wallet2}")

transfer = wallet1.transfer(0.00001, "eth", wallet2).wait()

print(f"Transfer successfully completed: {transfer}")
```

### Gasless USDC Transfers

To transfer USDC without needing to hold ETH for gas, you can use the `transfer` method with the `gasless` option set to `True`.

```python
# Create a new wallet wallet3 to transfer funds to.
wallet3 = Wallet.create()

print(f"Wallet successfully created: {wallet3}")

# Fund the wallet with USDC with a faucet transaction.
usdc_faucet_tx = wallet1.faucet("usdc")

# Wait for the faucet transaction to complete.
usdc_faucet_tx.wait()

print(f"Faucet transaction successfully completed: {usdc_faucet_tx}")

transfer = wallet1.transfer(0.00001, "usdc", wallet3, gasless=True).wait()
```

## Listing Transfers

```python
# Return list of all transfers. This will paginate and fetch all transfers for the address.
list(address.transfers())
```

## Trading Funds

See [Trades](https://docs.cdp.coinbase.com/wallets/docs/trades) for more information.

```python
wallet = Wallet.create("base-mainnet")

print(f"Wallet successfully created: {wallet}")
print(f"Send `base-mainnet` ETH to wallets default address: {wallet.default_address.address_id}")

trade = wallet.trade(0.00001, "eth", "usdc").wait()

print(f"Trade successfully completed: {trade}")
```

## Listing Trades

```python
# Return list of all trades. This will paginate and fetch all trades for the address.
list(address.trades())
```

## Creating a Webhook
A webhook is a way to provide other applications with real-time information from the blockchain. When an event occurs on a blockchain address, it can send a POST request to a URL you specify. You can create a webhook to receive notifications about events that occur in your wallet or crypto address, such as when a user makes a transfer.
```python
from cdp.client.models.webhook import WebhookEventType
from cdp.client.models.webhook import WebhookEventFilter

wh1 = Webhook.create(
    notification_uri="https://your-app.com/callback",
    event_type=WebhookEventType.ERC20_TRANSFER,
    event_filters=[WebhookEventFilter(from_address="0x71d4d7d5e9ce0f41e6a68bd3a9b43aa597dc0eb0")]
)
print(wh1)
```

## Creating a Webhook On A Wallet
A webhook can be attached to an existing wallet to monitor events that occur on the wallet, i.e. all addresses associated with this wallet. A list of supported blockchain events can be found [here](https://docs.cdp.coinbase.com/get-started/docs/webhooks/event-types).
```python
import cdp

wallet1 = Wallet.create()
wh1 = wallet1.create_webhook("https://your-app.com/callback")
print(wh1)
```

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

