alchemy_api/api/
notify.rs

1use crate::types::chain::AlchemyChain;
2use ethers_core::types::Address;
3use serde::{Deserialize, Serialize};
4
5mod create_webhook;
6mod delete_webhook;
7mod nft_filters;
8mod team_webhooks;
9mod update_webhook;
10mod webhook_addresses;
11
12pub use create_webhook::CreateWebhook;
13pub use delete_webhook::DeleteWebhook;
14pub use nft_filters::{
15    GetWebhookNftFilters, GetWebhookNftFiltersResponse, UpdateWebhookNftFilters,
16    UpdateWebhookNftMetadataFilters,
17};
18pub use team_webhooks::{GetAllWebhooks, GetAllWebhooksResponse};
19pub use update_webhook::UpdateWebhook;
20pub use webhook_addresses::{
21    GetWebhookAddresses, GetWebhookAddressesResponse, ReplaceWebhookAddresses,
22    UpdateWebhookAddresses,
23};
24
25/// Webhook information.
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct Webhook {
28    /// Unique ID for given webhook.
29    id: String,
30    /// Network of webhook.
31    network: AlchemyChain,
32    /// Type of webhook, `null` if test webhook.
33    webhook_type: Option<WebhookType>,
34    /// URL endpoint where webhook is sent.
35    webhook_url: String,
36    /// `true` if webhook is active, `false` if not active.
37    is_active: bool,
38    /// Timestamp webhook was created.
39    time_created: u64,
40    /// List of addresses being tracked, `null` if not address activity webhook.
41    addresses: Option<Vec<Address>>,
42    /// Webhook version (`v1` or `v2`).
43    version: WebhookVersion,
44    /// Signing key for given webhook.
45    signing_key: String,
46}
47
48/// Returns webhook creation data/updated webhook status.
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct WebhookResponse {
51    data: Webhook,
52}
53
54impl WebhookResponse {
55    /// List of webhooks for your team.
56    pub fn data(&self) -> Webhook {
57        self.data.clone()
58    }
59}
60
61/// Webhook version (v1 or v2)
62#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)]
63#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
64pub enum WebhookType {
65    /// Custom Webhooks allows you to track any smart contract or marketplace activity, monitor any
66    /// contract creation, or any other on-chain interaction. This gives you infinite data access
67    /// with precise filter controls to get the blockchain data you need.
68    CustomWebhooks,
69    /// The Mined Transaction webhook notifies your app when a transaction sent through your app
70    /// (using your API key) gets mined. This is useful for you to further notify the users of your
71    /// app about the status of the transaction.
72    MinedTransaction,
73    /// The Dropped Transaction webhook notifies your app when a transaction sent through your app
74    /// (using your API key) gets dropped. This is useful for you to further notify the users of
75    /// your app about the status of the transaction.
76    DroppedTransaction,
77    /// Alchemy's Address Activity webhook tracks all ETH, ERC20, ERC721 and ERC1155 transfers.
78    /// This provides your app with real-time state changes when an address sends/receives tokens
79    /// or ETH. You can specify the addresses for which you want to track this activity. A maximum
80    /// of 50,000 addresses can be added to a single webhook.
81    #[default]
82    AddressActivity,
83    /// The NFT Activity webhook allows you to track ERC721 and ERC1155 token contracts for NFTs.
84    /// This provides your app with real-time state changes when an NFT is transferred between
85    /// addresses.
86    NftActivity,
87    /// The NFT Metadata Updates webhook allows you to track metadata updates for ERC721 and
88    /// ERC1155 token contracts for Ethereum and Polygon NFTs. This notifies your app when the
89    /// metadata for an NFT is updated.
90    NftMetadataUpdate,
91}
92
93/// Webhook version (v1 or v2)
94#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
95pub enum WebhookVersion {
96    /// V1 Webhook.
97    V1,
98    /// V2 Webhook.
99    V2,
100}
101
102/// Returns empty object.
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct EmptyResponse {}