Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ env/
.\#*
.projectile

.idea/
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

## [0.0.7] - 2024-10-25

### Added

- Include ERC20 and ERC721 token transfer information into transaction content.
- Support for wallet and address webhooks to trigger based on onchain activities.

## [0.0.6] - 2024-10-17

### Added
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,31 @@ print(f"Trade successfully completed: {trade}")
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.

2 changes: 2 additions & 0 deletions cdp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from cdp.wallet import Wallet
from cdp.wallet_address import WalletAddress
from cdp.wallet_data import WalletData
from cdp.webhook import Webhook

__all__ = [
"__version__",
Expand All @@ -24,6 +25,7 @@
"Wallet",
"WalletAddress",
"WalletData",
"Webhook",
"Asset",
"Transfer",
"Address",
Expand Down
2 changes: 1 addition & 1 deletion cdp/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.6"
__version__ = "0.0.7"
18 changes: 18 additions & 0 deletions cdp/api_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from cdp.client.api.transaction_history_api import TransactionHistoryApi
from cdp.client.api.transfers_api import TransfersApi
from cdp.client.api.wallets_api import WalletsApi
from cdp.client.api.webhooks_api import WebhooksApi


class ApiClients:
Expand All @@ -21,6 +22,7 @@ class ApiClients:
Attributes:
_cdp_client (CdpApiClient): The CDP API client used to initialize individual API clients.
_wallets (Optional[WalletsApi]): The WalletsApi client instance.
_webhooks (Optional[WebhooksApi]): The WebhooksApi client instance.
_addresses (Optional[AddressesApi]): The AddressesApi client instance.
_external_addresses (Optional[ExternalAddressesApi]): The ExternalAddressesApi client instance.
_transfers (Optional[TransfersApi]): The TransfersApi client instance.
Expand All @@ -40,6 +42,7 @@ def __init__(self, cdp_client: CdpApiClient) -> None:
"""
self._cdp_client: CdpApiClient = cdp_client
self._wallets: WalletsApi | None = None
self._webhooks: WebhooksApi | None = None
self._addresses: AddressesApi | None = None
self._external_addresses: ExternalAddressesApi | None = None
self._transfers: TransfersApi | None = None
Expand All @@ -66,6 +69,21 @@ def wallets(self) -> WalletsApi:
self._wallets = WalletsApi(api_client=self._cdp_client)
return self._wallets

@property
def webhooks(self) -> WebhooksApi:
"""Get the WebhooksApi client instance.

Returns:
WebhooksApi: The WebhooksApi client instance.

Note:
This property lazily initializes the WebhooksApi client on first access.

"""
if self._webhooks is None:
self._webhooks = WebhooksApi(api_client=self._cdp_client)
return self._webhooks

@property
def addresses(self) -> AddressesApi:
"""Get the AddressesApi client instance.
Expand Down
4 changes: 4 additions & 0 deletions cdp/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from cdp.client.api.contract_invocations_api import ContractInvocationsApi
from cdp.client.api.external_addresses_api import ExternalAddressesApi
from cdp.client.api.networks_api import NetworksApi
from cdp.client.api.onchain_identity_api import OnchainIdentityApi
from cdp.client.api.server_signers_api import ServerSignersApi
from cdp.client.api.smart_contracts_api import SmartContractsApi
from cdp.client.api.stake_api import StakeApi
Expand Down Expand Up @@ -96,6 +97,9 @@
from cdp.client.models.nft_contract_options import NFTContractOptions
from cdp.client.models.network import Network
from cdp.client.models.network_identifier import NetworkIdentifier
from cdp.client.models.onchain_name import OnchainName
from cdp.client.models.onchain_name_list import OnchainNameList
from cdp.client.models.onchain_name_text_records_inner import OnchainNameTextRecordsInner
from cdp.client.models.payload_signature import PayloadSignature
from cdp.client.models.payload_signature_list import PayloadSignatureList
from cdp.client.models.read_contract_request import ReadContractRequest
Expand Down
1 change: 1 addition & 0 deletions cdp/client/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from cdp.client.api.contract_invocations_api import ContractInvocationsApi
from cdp.client.api.external_addresses_api import ExternalAddressesApi
from cdp.client.api.networks_api import NetworksApi
from cdp.client.api.onchain_identity_api import OnchainIdentityApi
from cdp.client.api.server_signers_api import ServerSignersApi
from cdp.client.api.smart_contracts_api import SmartContractsApi
from cdp.client.api.stake_api import StakeApi
Expand Down
Loading