Understanding Signing of Transaction – Blockchain [Part #5]

Note: This blog post is meant for beginners. If you have experience with web3 nd blockchain, you might not find this as useful, but I encourage you to maybe stick around anyway.

Hey everyone! In our previous blog post, we learned how transactions work in the blockchain. Today, let’s learn how a user signs these transactions, the role of private and public keys, and how they’re generated. This step is crucial for ensuring security and authenticity in digital transactions.

What are Public and Private Keys?

If you’ve used SSH, you’re likely familiar with public and private keys. In blockchain, the concept is similar. As the names suggest, public keys are meant to be shared, much like your home address, allowing others to send you NFTs or cryptocurrency. Private keys, on the other hand, should remain confidential think of them as the keys to your digital home. They are crucial for accessing your digital assets and signing transactions to prove your identity as the sender.

Security in blockchain is most important and you are responsible for your own security, if compromised, it’s tough to recover lost funds or secure your assets again.

How are These Keys Generated?

The blockchain uses cryptographic algorithms to generate these keys. One of the most popular methods, especially on networks like Ethereum, is the Elliptic Curve Digital Signature Algorithm (ECDSA). This algorithm is renowned for creating secure and unique keys that are almost impossible to tamper with.

ECDSA starts by generating a private key, essentially just a random number. From this private key, your public key is derived through some serious math specifically, elliptic curve multiplication. And to be honest, even I don’t completely understand all the math behind it!

You can check out this DEMO to see how public keys are generated from a private key.

Signing of Transaction works in Ethereum:

When you initiate a transaction, like sending some Ether, ECDSA signs this transaction using your private key. This signature acts as proof that you own the Ether, all without revealing your private key.

Here’s another DEMO that helps understand how a message is signed using a private key and verified using its public key. I’ve written a secret message and signed it; when you click on verify, you can see my public key and the message signature.

When our transaction is broadcast to the network, anyone in the Ethereum network can use your public key to verify that your signature matches and validate the transaction. This verification ensures that the transaction is legitimate and indeed signed by you.

The demo I mentioned earlier can also be used to understand how a transaction stating we sent ether to an address can be verified by the nodes on the Ethereum network.

Using ECDSA, Ethereum ensures that each transaction is secure and authenticated, providing an unbreakable seal on your digital transactions.

Firstly, ECDSA helps generate a private key, which is just a random number. From this private key, your public key is derived. You can easily get the public key from the private key, but not the other way around. This involves some serious math and tbh even i don’t complete understand the maths behind it, specifically the elliptical curve multiplication.

When we initiate a transaction, say sending some Ether, ECDSA comes into play to sign this transaction with our private key. This signature is a way to prove that you are the owner of the Ether without revealing your private key.

Here is a DEMO which can be used to understand how message is signed using private key and can be verified using its public key

I have write a secret message and signed it now when i click on verify you can see my public key and message signature.

On the flip side, when our transaction is broadcast to the network, anyone in the Ethereum network can use your public key to verify that your signature matches and validate the transaction. This verification process ensures that the transaction is legitimate and that it was indeed you who signed it.

The above demo was just signed a simple data but here we can also sign a transaction stating we sent the ether to a address and similarly that can be verifies by the nodes on the ethereum network

Using ECDSA, Ethereum ensures that each transaction is secure and authenticated, all without ever exposing your private key. It’s like having an unbreakable seal on your digital transactions.

Public Key and Ethereum Addresses

After understanding keys, let’s talk about Ethereum addresses. our Ethereum address, which others use to send us Ether, is derived from our public key. However, it’s not our public key itself but a shorter, more usable version that’s generated through cryptographic hashing.

First, Our public key is derived from this private key. Next, Keccak-256 hashing is performed on the public key. Keccak-256 is a type of cryptographic hash function which takes the public key and converts it into a 256-bit fixed length hash value. Finally we get the Ethereum address by truncating the hashed value to the last 20 bytes or 40 hexadecimal characters. This results in your unique Ethereum address used for transactions.

How Does Metamask Create an Account?

Metamask is not just a tool for managing cryptocurrencies but also a gateway to accessing the decentralized web. When creating a new account, Metamask generates a mnemonic phrase, also known as a seed phrase. This phrase is a set of words generated from your private key and is used to recover your account if needed.

Secret Phrase vs. Mnemonic:

  • Secret Phrase: A single key or a combination of words used once for a specific transaction or login.
  • Mnemonic: A series of words generated from your private key that can be used to recover your accounts.

Today, we’ve covered how transactions are signed in the blockchain, mechanics of public and private keys, and the role of wallets like Metamask. These elements ensure that your digital transactions are secure and verifiable. In the next blogpost we are going to discuss about GAS fees.

Leave a Reply