V2 Alchemy Notify
Guide for using Version 2 of Alchemy Notify on Layer 2s (Polygon, Optimism, and Arbitrum).

Note: The information below only applies to Alchemy Notify on Polygon, Optimism, and Arbitrum. For Webhooks on Ethereum see the Using Alchemy Notify/Webhooks doc.

To learn more about how webhooks work, check out this guide.

Types of Webhooks

There are two types of webhooks that are supported on Layer 2 chains: mined transactions and dropped transactions.

Webhook Format

Both webhook types have the same format:
  • webhookId: Unique id for the webhook that this event was sent to
  • id: Unique id of the event itself
  • createdAt: Timestamp that the event was created
  • type: Type of webhook event, can be "MINED_TRANSACTION" or "DROPPED_TRANSACTION"
  • event: Object - event object, see mined transaction object and dropped transaction object.
    • appId: Unique ID for Alchemy app configured with this webhook
    • network: Network for the event, can be ARB_MAINNET, ARB_RINKEBY, MATIC_MAINNET, MATIC_MUMBAI, OPT_MAINNET, OPT_KOVAN
    • transaction: transaction object
1
{
2
"webhookId": "wh_octjglnywaupz6th",
3
"id": "whevt_ogrc5v64myey69ux",
4
"createdAt": "2021-12-07T03:52:45.899Z",
5
"type": TYPE_STRING,
6
"event": OBJECT
7
}
Copied!

1. Mined Transactions

The Mined Transaction Webhook is used to notify your app anytime a transaction gets successfully mined that was sent through your Alchemy API key. This is extremely useful if you want to notify customers the moment their transactions goes through.

Example Response

1
{
2
"webhookId": "wh_octjglnywaupz6th",
3
"id": "whevt_ogrc5v64myey69ux",
4
"createdAt": "2021-12-07T03:52:45.899Z",
5
"type": "MINED_TRANSACTION",
6
"event": {
7
"appId": "j6tqmhfxlu9pa5r7",
8
"network": "MATIC_MUMBAI",
9
"transaction": {
10
"blockHash": "0x0a50cb2068418da0d7746155be39cff624aaf6fca58fa7f86f139999947433db",
11
"blockNumber": "0x154f434",
12
"from": "0x829e20741ee472f628b260a591f9f78fb1a555f8",
13
"gas": "0x5208",
14
"gasPrice": "0xdf8475800",
15
"hash": "0xc981aed4304084ddf2b82859c80dd31334fad3bcf2aa7ee15dfd646af0889b7d",
16
"input": "0x",
17
"nonce": "0x8",
18
"to": "0x4577d79fc84838aee64ba8be8d250981dd4f3876",
19
"transactionIndex": "0x1",
20
"value": "0x0",
21
"type": "0x0",
22
"v": "0x27125",
23
"r": "0xc07a6670796726674e213c4cf61763b59490b1b1c992b9323a1aad5e3c2cea88",
24
"s": "0x22ce350c260b3dbd1ebc06ca00b18c127efd6c1b31136a104de1a6ea4aa3c0d2"
25
}
26
}
27
}
Copied!

2. Dropped Transactions

The Dropped Transactions Webhook is used to notify your app anytime a transaction gets dropped that was sent through your Alchemy API key.
Example Response
1
{
2
"webhookId": "wh_octjglnywaupz6th",
3
"id": "whevt_ogrc5v64myey69ux",
4
"createdAt": "2021-12-07T03:52:45.899Z",
5
"type": "DROPPED_TRANSACTION",
6
"event": {
7
"appId": "j6tqmhfxlu9pa5r7",
8
"network": "OPT_MAINNET",
9
"transaction": {
10
"hash": "0x5a4bf6970980a9381e6d6c78d96ab278035bbff58c383ffe96a0a2bbc7c02a4b",
11
"blockHash": null,
12
"blockNumber": null,
13
"from": "0x8a9d69aa686fa0f9bbdec21294f67d4d9cfb4a3e",
14
"gas": "0x5208",
15
"gasPrice": "0x165a0bc00",
16
"input": "0x",
17
"nonce": "0x2f",
18
"r": "0x575d26288c1e3aa63e80eea927f54d5ad587ad795ad830149837258344a87d7c",
19
"s": "0x25f5a3abf22f5b8ef6ed307a76e670f0c9fb4a71fab2621fce8b52da2ab8fe82",
20
"to": "0xd69b8ff1888e78d9c337c2f2e6b3bf3e7357800e",
21
"transactionIndex": null,
22
"v": "0x1c",
23
"value": "0x1bc16d674ec80000"
24
}
25
}
26
}
Copied!

Webhook Signature and Security

If you want to make your webhooks extra secure, you can verify that they originated from Alchemy by generating a HMAC SHA-256 hash code using your unique webhook signing key.

1. Find your signing key

Navigate to the Notify page in your dashboard, click on the three dots for the webhook you want to get the signature for and copy the "signing key".

2. Validate the signature received

Every outbound request will contain a hashed authentication signature in the header which is computed by concatenating your signing key and request body then generating a hash using the HMAC SHA256 hash algorithm.
In order to verify this signature came from Alchemy, you simply have to generate the HMAC SHA256 hash and compare it with the signature received.

Example Request Header

1
POST /yourWebhookServer/push HTTP/1.1
2
Content-Type: application/json;
3
X-Alchemy-Signature: your-hashed-signature
Copied!

Example Signature Validation Function

JavaScript
Python
1
function isValidSignature(request) {
2
const signingKey = 'Signing key from by Alchemy dashboard for your Webhook';
3
const headers = request.headers;
4
const signature = headers['x-alchemy-signature']; // Lowercase for NodeJS
5
const body = request.body;
6
const hmac = crypto.createHmac('sha256', token) // Create a HMAC SHA256 hash using the auth token
7
hmac.update(JSON.stringify(body), 'utf8') // Update the token hash with the request body using utf8
8
const digest = hmac.digest('hex');
9
return (signature === digest); // If signature equals your computed hash, return true
10
}
Copied!
1
import hmac
2
import hashlib
3
import json
4
def isValidSignature(request):
5
signingKey = 'Signing key from by Alchemy dashboard for your Webhook';
6
headers = request['headers'];
7
signature = headers['x-alchemy-signature'];
8
body = request['body'];
9
string_body = json.dumps(body, separators=(',', ':'))
10
digest = hmac.new(
11
bytes(token, 'utf-8'),
12
msg=bytes(string_body, 'utf-8'),
13
digestmod=hashlib.sha256
14
).hexdigest()
15
return (signature == digest);
Copied!
Last modified 1mo ago