Signed by a Private Key: Verifying a Blockchain Transaction
One of the most important ideas in blockchain is this: a transaction proves who authorized it without revealing the private key. That proof comes from digital signatures.
This post demonstrates that idea directly using Python. A private key is created, a wallet address is derived, a transaction is signed, and the signer’s address is recovered from the signed transaction itself.
No blockchain network is required. No node. No RPC calls. Just cryptography. The code used can be found in this GitHub repository.
The core idea
A blockchain transaction is not trusted because someone claims to have sent it. It is trusted because anyone can mathematically verify that the transaction was signed by the private key associated with the sender’s address.
If the recovered address matches the expected address, the signature is valid. That is the entire trust model.
If needed, install the eth-account package: $ pip install eth-account
from eth_account import Account
Step 1: Create a wallet
The example begins by creating a new Ethereum account. This produces a private key and the corresponding wallet address.
acct = Account.create()
private_key = acct.key
wallet_address = acct.address
At this point, an account has been created. The account object has a key, or private key, and an address, or wallet address:
- The private key should remain secret.
- The wallet address can be shared publicly.
- Anyone can verify signed transactions associated to this account.
Step 2: Build a transaction payload
Next, a simple Ethereum-style transaction is constructed. The structure mirrors a real transaction.
tx = {
"nonce": 0,
"gasPrice": 1_000_000_000,
"gas": 21000,
"to": "0x000000000000000000000000000000000000d1a6",
"value": 30000,
"data": b"",
"chainId": 1,
}
This transaction specifies:
- A transfer of 30000 wei
- A destination address
- Standard gas settings
- Ethereum mainnet as the target chain
Step 3: Sign the transaction
The critical step is signing the transaction using the private key.
signed_tx = Account.sign_transaction(tx, private_key)
The signed transaction contains a cryptographic signature and the raw transaction bytes, which together provide everything required for verification. The private key is never exposed.
Step 4: Recover the signer from the signature
Verification occurs by recovering the sender’s address directly from the signed transaction.
confirm_address = Account.recover_transaction(
signed_tx.raw_transaction
)
Ethereum signatures include enough information to reconstruct the public key, and therefore the wallet address, from the signature and transaction data.
Step 5: Verify the signature
The recovered address is compared to the expected wallet address.
print("wallet address:", wallet_address)
print("address recovered from the tx:", confirm_address)
print("valid:", wallet_address.lower() == confirm_address.lower())
If valid evaluates to True, the transaction could only have been signed by the holder of the corresponding private key.
Why this matters
This example captures the foundation of how trust works in blockchain systems. Private keys authorize actions, wallet addresses act as public identifiers, and transactions carry their own proof of authenticity. Because verification is mathematical rather than relational, network participants do not need to know or trust one another. Each node independently validates the same cryptographic facts and arrives at the same conclusion. That is how decentralized systems operate without central authorities.
Every blockchain node performs this verification before accepting a transaction into a block. If the recovered address does not match the sender’s address, the transaction is rejected regardless of who submitted it or where it originated.
A useful mental model
A transaction signature functions like a wax seal on a letter. The seal is visible to everyone and can be inspected by anyone, yet only one party could have created it. The recipient does not need to trust the messenger or the sender’s reputation. The seal itself is the proof. Blockchain transactions work the same way, with cryptography replacing physical seals.