{"id":18542722,"url":"https://github.com/coinbase/cdp-sdk-python","last_synced_at":"2025-04-12T22:37:15.340Z","repository":{"id":257806357,"uuid":"856592724","full_name":"coinbase/cdp-sdk-python","owner":"coinbase","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-27T22:51:19.000Z","size":1578,"stargazers_count":63,"open_issues_count":1,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-30T09:32:55.649Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coinbase.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-12T21:02:25.000Z","updated_at":"2024-11-27T21:10:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"1e378706-f693-4efa-b507-94a83b352f87","html_url":"https://github.com/coinbase/cdp-sdk-python","commit_stats":null,"previous_names":["coinbase/cdp-sdk-python"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcdp-sdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcdp-sdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcdp-sdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcdp-sdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coinbase","download_url":"https://codeload.github.com/coinbase/cdp-sdk-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643006,"owners_count":21138353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T20:09:56.682Z","updated_at":"2025-04-12T22:37:15.309Z","avatar_url":"https://github.com/coinbase.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CDP Python SDK\n\n[![PyPI version](https://img.shields.io/pypi/v/cdp-sdk?style=flat-square\u0026logo=python)](https://pypi.org/project/cdp-sdk/)\n[![PyPI - Weekly Downloads](https://img.shields.io/pypi/dw/cdp-sdk?style=flat-square)](https://pypistats.org/packages/cdp-sdk)\n\nThe CDP Python SDK enables the simple integration of crypto into your app.\nBy calling Coinbase's CDP APIs, the SDK allows you to provision crypto wallets,\nsend crypto into/out of those wallets, track wallet balances, and trade crypto from\none asset into another.\n\n\n*Note: As the SDK provides new capabilities and improves the developer experience, updates may occasionally include breaking changes. These will be documented in the [CHANGELOG.md](CHANGELOG.md) file.*\n\n## Documentation\n\n- [CDP API Documentation](https://docs.cdp.coinbase.com/platform-apis/docs/welcome)\n- [CDP SDK Python Documentation](https://coinbase.github.io/cdp-sdk-python/)\n\n## Requirements\n\n- Python 3.10+\n- Poetry for package management and tooling\n  - [Poetry Installation Instructions](https://python-poetry.org/docs/#installation)\n\n### Checking Python Version\n\nBefore 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:\n\n```bash\npython --version\npip --version\n```\n\nIf 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/).\nFor `pip`, refer to the [official pip documentation](https://pip.pypa.io/en/stable/installation/) for installation instructions.\n\n## Installation\n\n```bash\npip install cdp-sdk\n```\n\nif you prefer to manage dependencies with Poetry:\n\n```bash\npoetry add cdp-sdk\n```\n\n### Starting a Python REPL\n\nTo start a Python REPL:\n\n```bash\npython\n```\n\n## Quickstart\n\n### Creating a Wallet\n\nTo 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:\n\n```python\nfrom cdp import *\n\napi_key_name = \"Copy your API key name here.\"\n\napi_key_private_key = \"Copy your API key's private key here.\"\n\nCdp.configure(api_key_name, api_key_private_key)\n\nprint(\"CDP SDK has been successfully configured with CDP API key.\")\n```\n\nAnother way to initialize the SDK is by sourcing the API key from the JSON file that contains your API key,\ndownloaded from the CDP portal.\n\n```python\nCdp.configure_from_json(\"~/Downloads/cdp_api_key.json\")\n\nprint(\"CDP SDK has been successfully configured from JSON file.\")\n```\n\nThis will allow you to authenticate with the Platform APIs.\n\nIf you are using a CDP [Server-Signer](https://docs.cdp.coinbase.com/wallet-api/docs/serversigners) to manage your private keys, enable it with\n\n```python\nCdp.use_server_signer = True\n```\n\nNow create a wallet. Wallets are created with a single default address.\n\n```python\n# Create a wallet with one address by default.\nwallet1 = Wallet.create()\n\nprint(f\"Wallet successfully created: {wallet1}\")\n```\n\nWallets come with a single default address, accessible via `default_address`:\n\n```python\n# A wallet has a default address.\naddress = wallet1.default_address\n```\n\n### Funding a Wallet\n\nWallets do not have funds on them to start. For Base Sepolia testnet, we provide a `faucet` method to fund your wallet with\ntestnet ETH. You are allowed one faucet claim per 24-hour window.\n\n```python\n# Fund the wallet with a faucet transaction.\nfaucet_tx = wallet1.faucet()\n\n# Wait for the faucet transaction to complete.\nfaucet_tx.wait()\n\nprint(f\"Faucet transaction successfully completed: {faucet_tx}\")\n```\n\n### Transferring Funds\n\nSee [Transfers](https://docs.cdp.coinbase.com/wallets/docs/transfers) for more information.\n\nNow that your faucet transaction has successfully completed, you can send the funds in your wallet to another wallet.\nThe code below creates another wallet, and uses the `transfer` function to send testnet ETH from the first wallet to\nthe second:\n\n```python\n# Create a new wallet wallet2 to transfer funds to.\nwallet2 = Wallet.create()\n\nprint(f\"Wallet successfully created: {wallet2}\")\n\ntransfer = wallet1.transfer(0.00001, \"eth\", wallet2).wait()\n\nprint(f\"Transfer successfully completed: {transfer}\")\n```\n\n#### Gasless USDC Transfers\n\nTo transfer USDC without needing to hold ETH for gas, you can use the `transfer` method with the `gasless` option set to `True`.\n\n```python\n# Create a new wallet wallet3 to transfer funds to.\nwallet3 = Wallet.create()\n\nprint(f\"Wallet successfully created: {wallet3}\")\n\n# Fund the wallet with USDC with a faucet transaction.\nusdc_faucet_tx = wallet1.faucet(\"usdc\")\n\n# Wait for the faucet transaction to complete.\nusdc_faucet_tx.wait()\n\nprint(f\"Faucet transaction successfully completed: {usdc_faucet_tx}\")\n\ntransfer = wallet1.transfer(0.00001, \"usdc\", wallet3, gasless=True).wait()\n```\n\nBy default, gasless transfers are batched with other transfers, and might take longer to submit. If you want to opt out of batching, you can set the `skip_batching` option to `True`, which will submit the transaction immediately.\n\n```python\ntransfer = wallet1.transfer(0.00001, \"usdc\", wallet3, gasless=True, skip_batching=True).wait()\n```\n\n### Listing Transfers\n\n```python\n# Return list of all transfers. This will paginate and fetch all transfers for the address.\nlist(address.transfers())\n```\n\n### Trading Funds\n\nSee [Trades](https://docs.cdp.coinbase.com/wallets/docs/trades) for more information.\n\n```python\nwallet = Wallet.create(\"base-mainnet\")\n\nprint(f\"Wallet successfully created: {wallet}\")\nprint(f\"Send `base-mainnet` ETH to wallets default address: {wallet.default_address.address_id}\")\n\ntrade = wallet.trade(0.00001, \"eth\", \"usdc\").wait()\n\nprint(f\"Trade successfully completed: {trade}\")\n```\n\n### Listing Trades\n\n```python\n# Return list of all trades. This will paginate and fetch all trades for the address.\nlist(address.trades())\n```\n\n### Re-Instantiating Wallets\n\nThe SDK creates wallets with [Developer-Managed (1-1)](https://docs.cdp.coinbase.com/wallet-api/docs/wallets#developer-managed-wallets) keys by default, which means you are responsible for securely storing the keys required to re-instantiate wallets. The below code walks you through how to export a wallet and store it in a secure location.\n\n```python\n# Export the data required to re-instantiate the wallet. The data contains the seed, the ID of the wallet, and the network ID.\ndata = wallet.export_data()\n```\n\nIn order to persist the data for the wallet, you will need to implement a store method to store the data export in a secure location. If you do not store the wallet in a secure location you will lose access to the wallet and all of the funds on it.\n\n```python\n# You should implement the \"store\" method to securely persist the data object,\n# which is required to re-instantiate the wallet at a later time. For ease of use,\n# the data object is converted to a dictionary first.\nstore(data.to_dict())\n```\n\nFor convenience during testing, we provide a `save_seed` method that stores the wallet's seed in your local file system. This is an insecure method of storing wallet seeds and should only be used for development purposes.\n\nTo encrypt the saved data, set encrypt to `True`. Note that your CDP API key also serves as the encryption key for the data persisted locally. To re-instantiate wallets with encrypted data, ensure that your SDK is configured with the same API key when invoking `save_seed` and `load_seed`.\n\n```python\n# Pick a file to which to save your wallet seed.\nfile_path = \"my_seed.json\"\n\n# Set encrypt=True to encrypt the wallet seed with your CDP secret API key.\nwallet.save_seed(file_path, encrypt=True)\n\nprint(f\"Seed for wallet {wallet.id} successfully saved to {file_path}.\")\n```\n\nThe below code demonstrates how to re-instantiate a wallet from the data export.\n\n```python\n# You should implement the \"fetch\" method to retrieve the securely persisted data object,\n# keyed by the wallet ID.\nfetched_data = fetch(wallet.id)\n\n# imported_wallet will be equivalent to wallet.\nimported_wallet = Wallet.import_data(fetched_data)\n```\n\nTo import Wallets that were persisted to your local file system using `save_seed`, use the below code.\n\n```python\n# Get the unhydrated wallet from the server.\nfetched_wallet = Wallet.fetch(wallet.id)\n\n# You can now load the seed into the wallet from the local file.\n# fetched_wallet will be equivalent to imported_wallet.\nfetched_wallet.load_seed(file_path)\n```\n\n### Creating a Webhook\n\nA 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.\n\n```python\nfrom cdp.client.models.webhook import WebhookEventType\nfrom cdp.client.models.webhook import WebhookEventFilter\n\nwh1 = Webhook.create(\n    notification_uri=\"https://your-app.com/callback\",\n    event_type=WebhookEventType.ERC20_TRANSFER,\n    event_filters=[WebhookEventFilter(from_address=\"0x71d4d7d5e9ce0f41e6a68bd3a9b43aa597dc0eb0\")],\n    network_id=\"base-mainnet\"\n)\nprint(wh1)\n```\n\nIn the above example, parameter `network_id` is optional, if not provided, the default network is `base-sepolia`. Today we support Base mainnet and Base Sepolia networks.\n\n### Creating a Webhook On A Wallet\n\nA 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).\n\n```python\nimport cdp\n\nwallet1 = Wallet.create()\nwh1 = wallet1.create_webhook(\"https://your-app.com/callback\")\nprint(wh1)\n```\n\n## Examples\n\nExamples, demo apps, and further code samples can be found in the [CDP SDK Python Documentation](https://docs.cdp.coinbase.com/cdp-apis/docs/welcome).\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase%2Fcdp-sdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoinbase%2Fcdp-sdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase%2Fcdp-sdk-python/lists"}