
🔧 1. Generate Delegation Certificate
cardano-cli stake-address delegation-certificate \
--stake-verification-key-file stake.vkey \
--cold-verification-key-file pool.vkey \
--out-file delegation.cert
🧩 2. Python Script to Build This CBOR Structure Manually
Here is a simple Python script using the cbor2 library to generate this structure and save it as delegation.cert (just like cardano-cli would):
import cbor2
# Sample 28-byte Stake Key Hash (in bytes)
stake_key_hash = bytes.fromhex('d85a3b0f31ac99a96f515fdf2c86f2f4b1fa9ebdc5a74a4fa51a8f18d2b992e4')
# Sample 28-byte Pool ID (cold key hash in bytes)
pool_id = bytes.fromhex('e9b0a3707ce7c7804786b3d0c947f9aeb5480a21956d13c2fd35e3c2b1fbc567')
# CBOR structure for a stake delegation certificate
delegation_cert = [
2, # Certificate type: stake delegation
[0, stake_key_hash], # Credential type: KeyHash, Stake Key Hash
pool_id # Pool ID (Cold Key Hash)
]
# Serialize to CBOR
cbor_data = cbor2.dumps(delegation_cert)
# Save to file (simulating delegation.cert)
with open('delegation.cert', 'wb') as f:
f.write(cbor_data)
print("delegation.cert CBOR file generated successfully.")
CBOR Structure in Plain Text Output:

In CBOR Diagnostic Notation Output:

Breakdown:
| Position | Meaning | Value |
|---|---|---|
[0] | Certificate type (2) | Delegation certificate |
[1] | Stake Credential Array | [0, <28-byte keyhash>] |
[2] | Pool Key Hash (cold key) | 28-byte keyhash (Pool ID) |
Explanation
- Type
2means this is a delegation certificate. - The stake key hash is extracted from the
stake.vkeyfile and is used to identify the delegator. - The pool key hash (Pool ID) points to the target pool’s cold verification key.
🔍 3. Decode the generated file to verify its structure
You can view the hex content of the .cert file like this ( Hex dump ):
xxd -p delegation.cert
Or use Python:
import cbor2
with open('delegation.cert', 'rb') as f:
decoded = cbor2.load(f)
print(decoded)
Sample output (hex dump of CBOR structure):
8201825820d85a3b0f31ac99a96f515fdf2c86f2f4b1fa9ebdc5a74a4fa51a8f18d2b992e45820
e9b0a3707ce7c7804786b3d0c947f9aeb5480a21956d13c2fd35e3c2b1fbc567
🛠️ 4. Tools You Can Use:
| Purpose | Tool |
|---|---|
| CBOR decoding | https://cbor.me |
| Python decoding | cbor2 module |
| Hex dump | xxd -p file.cert |
| Pretty print CBOR (Haskell) | cardano-cli text-view (planned but limited) |
🚨 5. Notes:
- All these certificates are mandatory parts of staking operations.
- They are immutable once included in a block.
- You can inspect certificates before submitting a transaction to verify correctness.

Do you know what staking is ? Staking on the blockchain refers to the process where participants lock up a certain amount of cryptocurrency to support the operations and security of a blockchain network. In return, they earn rewards, typically in the form of additional cryptocurrency. Staking is often associated with proof-of-stake (PoS) or similar consensus mechanisms used by many blockchains.
