-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e945711
Showing
34 changed files
with
38,168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: e18c9f16e7b3b28894daf8085ec67a68 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# 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) | ||
|
||
## 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 | ||
``` | ||
|
||
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/). | ||
|
||
## 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." | ||
# Ensure that you are using double-quotes 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() | ||
``` | ||
|
||
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() | ||
|
||
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}") | ||
|
||
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. | ||
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. | ||
address.trades() | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
cdp.client.api package | ||
====================== | ||
|
||
Submodules | ||
---------- | ||
|
||
cdp.client.api.addresses\_api module | ||
------------------------------------ | ||
|
||
.. automodule:: cdp.client.api.addresses_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.assets\_api module | ||
--------------------------------- | ||
|
||
.. automodule:: cdp.client.api.assets_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.balance\_history\_api module | ||
------------------------------------------- | ||
|
||
.. automodule:: cdp.client.api.balance_history_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.contract\_events\_api module | ||
------------------------------------------- | ||
|
||
.. automodule:: cdp.client.api.contract_events_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.contract\_invocations\_api module | ||
------------------------------------------------ | ||
|
||
.. automodule:: cdp.client.api.contract_invocations_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.external\_addresses\_api module | ||
---------------------------------------------- | ||
|
||
.. automodule:: cdp.client.api.external_addresses_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.networks\_api module | ||
----------------------------------- | ||
|
||
.. automodule:: cdp.client.api.networks_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.server\_signers\_api module | ||
------------------------------------------ | ||
|
||
.. automodule:: cdp.client.api.server_signers_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.smart\_contracts\_api module | ||
------------------------------------------- | ||
|
||
.. automodule:: cdp.client.api.smart_contracts_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.stake\_api module | ||
-------------------------------- | ||
|
||
.. automodule:: cdp.client.api.stake_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.trades\_api module | ||
--------------------------------- | ||
|
||
.. automodule:: cdp.client.api.trades_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.transfers\_api module | ||
------------------------------------ | ||
|
||
.. automodule:: cdp.client.api.transfers_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.users\_api module | ||
-------------------------------- | ||
|
||
.. automodule:: cdp.client.api.users_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.validators\_api module | ||
------------------------------------- | ||
|
||
.. automodule:: cdp.client.api.validators_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.wallet\_stake\_api module | ||
---------------------------------------- | ||
|
||
.. automodule:: cdp.client.api.wallet_stake_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.wallets\_api module | ||
---------------------------------- | ||
|
||
.. automodule:: cdp.client.api.wallets_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
cdp.client.api.webhooks\_api module | ||
----------------------------------- | ||
|
||
.. automodule:: cdp.client.api.webhooks_api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: cdp.client.api | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
Oops, something went wrong.